NutzCN Logo
问答 测试demo代码分页查询代码调试不报错,求解
发布于 2041天前 作者 wx_2jk6i7mpius707s625cs 1494 次浏览 复制 上一个帖子 下一个帖子
标签:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户列表</title>
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js"></script>
<script type="text/javascript">
    var pageNumber = 1;
    var pageSize = 10;
    var base = '<%=request.getAttribute("base")%>';
    function user_reload() {
        $.ajax({
            url : base + "/cards/query",
            data : $("#user_query_form").serialize(),
            dataType : "json",
            success : function(data) {
            	console.info(data);
                $("#user_count").html("共"+data.pager.recordCount+"个用户, 总计"+data.pager.pageCount+"页");
                var list_html = "";
                for (var i=0;i<data.list.length;i++) {
                    var user = data.list[i];
                    console.log(user);
                    var tmp = "\n<p>" + user.cardId + " " + user.cardNumber
                              + " <button onclick='user_update(" + user.cardId +");'>修改</button> "
                              + " <button onclick='user_delete(" + user.cardId +");'>删除</button> "
                              + "</p>";
                    list_html += tmp;
                }
                $("#user_list").html(list_html);
            }
        });
    }
    $(function() {
        user_reload();
        $("#user_query_btn").click(function() {
            user_reload();
        });
        $("#user_add_btn").click(function() {
            $.ajax({
                url : base + "/user/add",
                data : $("#user_add_form").serialize(),
                dataType : "json",
                success : function(data) {
                    if (data.ok) {
                        user_reload();
                        alert("添加成功");
                    } else {
                        alert(data.msg);
                    }
                }
            });
        });
    });
    function user_update(userId) {
        var passwd = prompt("请输入新的密码");
        if (passwd) {
            $.ajax({
                url : base + "/user/update",
                data : {"id":userId,"password":passwd},
                dataType : "json",
                success : function (data) {
                    if (data.ok) {
                        user_reload();
                        alert("修改成功");
                    } else {
                        alert(data.msg);
                    }
                }
            });
        }
    };
    function user_delete(userId) {
        var s = prompt("请输入y确认删除");
        if (s == "y") {
            $.ajax({
                url : base + "/user/delete",
                data : {"id":userId},
                dataType : "json",
                success : function (data) {
                    if (data.ok) {
                        user_reload();
                        alert("删除成功");
                    } else {
                        alert(data.msg);
                    }
                }
            });
        }
    };
</script>
</head>
<body>
<div>
    <form action="#" id="user_query_form">
        条件<input type="text" name="name">
        页数<input type="text" name="pageNumber" value="1">
        每页<input type="text" name="pageSize" value="10">
    </form>
    <button id="user_query_btn">查询</button>
    <p>---------------------------------------------------------------</p>
    <p id="user_count"></p>
    <div id="user_list">

    </div>
</div>
<div>
    <p>---------------------------------------------------------------</p>
</div>
<div id="user_add">
    <form action="#" id="user_add_form">
        用户名<input name="name">
        密码<input name="password">
    </form>
    <button id="user_add_btn">新增</button>
</div>
</body>
</html>
 @At
	 @Ok(">>:/page/admin/page/page/adminMg/table.jsp")
	 public Object query(HttpSession httpSession, @Param("..")Pager pager) {
	      //Cnd cnd = Strings.isBlank(name)? null : Cnd.where("name", "like", "%"+name+"%");
	      QueryResult qr = new QueryResult();
	      String Phone =httpSession.getAttribute("me").toString();
	      List<VipCards> cards = VipCardsDao.getCards(Phone);
	      qr.setList(cards);
	      pager.setRecordCount(cards.size());
	      qr.setPager(pager);
	      return qr; //默认分页是第1页,每页20条
	  }
2019-04-15 13:54:12,590 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [GET] path=/cards/query : UserCardsAction.query(UserCardsAction.java:36)
2019-04-15 13:54:12,591 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:165) DEBUG - Get 'userCardsAction'<class net.wendal.nutzbook.action.UserCardsAction>
2019-04-15 13:54:12,761 net.wendal.nutzbook.dao.UserDao.checkUser(UserDao.java:223) INFO  - 1778762
15 回复

user_reload() 方法下面成功后回应data打印不出来。猜测是没有成功

@Ok(">>:/page/admin/page/page/adminMg/table.jsp")

重定向是带不了数据过去的, 用 ->

另外,ajax请求是不会重定向的

</div>
<div id="user_info_div" style="display:none">
    <p id="userInfo"></p>
    <a href="${base}/user/logout">登出</a>
</div>
    <div class="buy_cart" onclick="location.href='${base}/cards/query'">卡信息查询</div> 
</body>

</html>

登录页面添加了一个跳转执行完毕后返回一个带有结果的table

之前跳转后可以出现查询分页结果

{"list":[{"id":0,"cardId":"1437767","cardNumber":"990100006590zf"}, {"id":0,"cardId":"1790949","cardNumber":"123456789012zf1"}, {"id":0,"cardId":"1790951","cardNumber":"123456789012"}, {"id":0,"cardId":"1826756","cardNumber":"000000000000"}, {"id":0,"cardId":"1827005","cardNumber":"000000000001"}, {"id":0,"cardId":"1827206","cardNumber":"000000000002"}, {"id":0,"cardId":"2111088","cardNumber":"098765432111"}, {"id":0,"cardId":"2111089","cardNumber":"098765432112"}, {"id":0,"cardId":"4536610","cardNumber":"990117079998"}],"pager":{"pageNumber":1,"pageSize":20,"pageCount":1,"recordCount":9}}
 @At
	 //@Ok(">>:/page/admin/page/page/adminMg/table.jsp")
	 @Ok("json")
	 public Object query(HttpSession httpSession, @Param("..")Pager pager) {
	      //Cnd cnd = Strings.isBlank(name)? null : Cnd.where("name", "like", "%"+name+"%");
	      QueryResult qr = new QueryResult();
	      String Phone =httpSession.getAttribute("me").toString();
	      List<VipCards> cards = VipCardsDao.getCards(Phone);
	      qr.setList(cards);
	      pager.setRecordCount(cards.size());
	      qr.setPager(pager);
	      return qr; //默认分页是第1页,每页20条
	  }

一个请求干不了两件事

嗯是的,我希望返回分页结果但是data里面没有东西是什么原因啊。

也不是没东西是打印不显示,那段代码不走了

@Ok("json:full")

好的我的目的是不想返json 的,而是期望返回列表jsp刚才那一段是向您展示一下返回里面有东西

其实这里可以直接跳页面执行ajax成功后返回数据。

</div>
    <div class="buy_cart" onclick="location.href='${base}/page/admin/page/page/adminMg/table.jsp'">卡信息查询</div> 
</body>

外部跳转带不了数据,开头就说了

出来了...下面这段代码是可以静态加载的啊。

 $(function() {
        user_reload();
        $("#user_query_btn").click(function() {
            user_reload();
        });
	 @At
	 @Ok("json:full")
	 public Object query(HttpSession httpSession, @Param("..")Pager pager) {
	      //Cnd cnd = Strings.isBlank(name)? null : Cnd.where("name", "like", "%"+name+"%");
	      QueryResult qr = new QueryResult();
	      String Phone =httpSession.getAttribute("me").toString();
	      List<VipCards> cards = VipCardsDao.getCards(Phone);
	      qr.setList(cards);
	      pager.setRecordCount(cards.size());
	      qr.setPager(pager);
	      return qr; //默认分页是第1页,每页20条
	  }
添加回复
请先登陆
回到顶部