MAVEN jq+ajax实现简单分页

jsp页面

<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script><!-- 如果使用本地路径,新手推荐使用绝对路径(不容易出错)-->
</head>
<body>
    <input type="button" value="下一页" id="nextPage">
    <input type="button" value="上一页" id="prePage" disabled>
    <table id="info">
        <thead>
            <tr>
                <td>id</td>
                <td>姓名</td>
            </tr>
        </thead>
        <tbody>

        </tbody>

    </table>
    <input type="hidden"  id="currentPage"><!-- 存储当前页信息-->
    <script type="text/javascript">
    // 页面初始化调用winload
        $(function() {
            winload(1,5);
        });
        $("#prePage").click(function(){
            winload(eval($("#currentPage").val())-1,5);
        });// 字符串转数字
        $("#nextPage").click(function(){
            winload(eval($("#currentPage").val())+1,5);
        });
        //查询数据并添加
        function winload(currentPage,currentCount) {
            $.ajax({
                        url : "pageList.uu",//controller层
                        type : "post",
                        dataType : "json",
                        data : {
                            "currentPage" : currentPage,
                            "currentCount" : currentCount
                        },
                        success : function(data) {
                            $("#currentPage").val(data.currentPage);
                            var s = "";
                            $.each(data.list,function(i,e){
                                s+='<tr><td>'+e.id+'</td><td>'+e.name+'</td></tr>';
                            }); 
                            $("#info tbody").empty();
                            //清空原有查询数据
                            $("#info").append(s);
                            if(eval($("#currentPage").val())==1){
                                $("#prePage").attr("disabled","disabled");//第一页添加禁止点击
                            }else{
                                $("#prePage").removeAttr("disabled");
                            }
                            if(data.totalPage==$("#currentPage").val()){
                                $("#nextPage").attr("disabled","disabled");
                            }else{
                                $("#nextPage").removeAttr("disabled");
                            }
                        }
                    })
        }
    </script>
</body>

impl层

public Map<String, Object> pageDel(int currentPage, Integer currentCount) {
        int startPage=(currentPage-1)*currentCount;
        //计算起始行数
        List<User> list = pageList(startPage, currentCount);//mysql查询当前页面数据
        int num = userTotalPage();//计算总用户条数
        int totalPage = (num + currentCount - 1) / currentCount;//计算总页数
        Map<String, Object> map = new HashMap<>();
        map.put("currentPage", currentPage);
        map.put("list", list);
        map.put("totalPage", totalPage);
        return map;//放置map json返回
    }

mapper xml里

<resultMap type="com.huwa.model.User" id="User"></resultMap>
<select id="userTotalPage" resultType="Integer">
        SELECT COUNT(*) FROM t_user
    </select>
<select id="pageList" resultMap="User">
        SELECT * from t_user 
        LIMIT #{startPage},#{currentCount}
    </select>

新手,写的是最简单的一种,其实这个难得是页面上的追加append,其他的也还好

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值