PageHelper分页

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<body>
<div class="container">
    <!-- 标题 -->
    <div class="row">
        <div class="col-md-12">
            <h1>SSM-CRUD</h1>
        </div>
    </div>
    <!-- 显示表格数据 -->
    <div class="row">
        <div class="col-md-12">
            <table class="table table-hover" id="emps_table">
                <thead>
                <tr>
                    <th>#</th>
                    <th>Name</th>
                    <th>sex</th>
                    <th>email</th>
                    <th>d_id</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="emps_table tbody">
                <tr>

                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div id="fy">

    </div>
</div>
</body>
</html>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
  $(function () {
         to_Page(1);
      });
   function to_Page(pn) {
       $.ajax({
           url:"/getAll",
           data:"pn="+pn,
           type:"GET",
           success:function(result){
               //console.log(result);
               
               build_emps_table(result);
              
              
               build_page_nav(result);
           }
       });
   }
  function build_emps_table(result){
      //清空table表格
      $("#emps_table tbody").empty();
      var emps = result.pageInfo.list;
      $.each(emps,function(index,item){
          var empIdTd = $("<td></td>").append(item.id);
          var empNameTd = $("<td></td>").append(item.name);
          var genderTd = $("<td></td>").append(item.sex);
          var emailTd = $("<td></td>").append(item.email);
          var deptNameTd = $("<td></td>").append(item.dId);
          $("<tr></tr>")
              .append(empIdTd)
              .append(empNameTd)
              .append(genderTd)
              .append(emailTd)
              .append(deptNameTd)
              .appendTo("#emps_table tbody");
      });
  }
  function build_page_nav(result) {
        $("#fy").empty();
        var ul=$("<ul></ul>").addClass("pagination");
        var firstPage=$("<li></li>").append($("<a></a>").attr("herf","#").append("首页"));
        firstPage.click(function () {
              to_Page(1);
        })
        ul.append(firstPage);
        var nav=result.pageInfo.navigatepageNums;
        $.each(nav,function (index,item) {
            var  numli=$("<li></li>").append($("<a></a>").attr("herf","#").append(item));
            if(result.pageInfo.pageNum == item){
                numli.addClass("active");
            }
            numli.click(function(){
                to_Page(item);
            });
            ul.append(numli);
        })
      var lastPage=$("<li></li>").append($("<a></a>").attr("herf","#").append("末页"));
      lastPage.click(function () {
          to_Page(result.pageInfo.pages);
      })
      ul.append(lastPage);
      var navEle = $("<nav></nav>").append(ul);
      navEle.appendTo("#fy");
  }
</script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值