您的位置 首页 技术

使用Layui表格实现后台分页的方法

使用Layui表格实现后台分页的方法: <table class="layui-table" lay-data="{width: 892, he…

使用Layui表格实现后台分页的方法:

<table class="layui-table" lay-data="{width: 892, height:332,url:'', page:true, id:'idTest'}" lay-filter="demo">  <thead>    <tr>      <th lay-data="{type:'checkbox', fixed: 'left'}"></th>      <th lay-data="{field:'id', width:80, sort: true, fixed: true}">id</th>      <th lay-data="{field:'menubarid', width:80}">菜单id</th>      <th lay-data="{field:'name', width:80, sort: true}">菜名</th>      <th lay-data="{field:'price', width:80}">价格</th>      <th lay-data="{field:'status', width:160}">状态</th>      <th lay-data="{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}"></th>    </tr>  </thead></table>

使用layui自动渲染生成表格,默认以get方式从前端获得参数page和limit

int page = Integer.parseInt(request.getParameter("page"));int limit = Integer.parseInt(request.getParameter("limit"));int count = menuDao.searchcount();             // 查找数据条数int page_temp = page;int limit_temp = limit;if (count < page * limit) {limit = count - (page - 1) * limit;}page = (page_temp - 1) * limit_temp;

使用的是mysql,第一条是查找行数目,第二条是分页查询语句,把page和limit分别传到两个问号里就行了。

 select  count(*) from menu select * from menu limit ?,?

最后转为json前把count的值改为从sql查询得到的行数目。

String layjson ="{\"code\":0,\"msg\":\"\",\"count\":"+getcount()+",\"data\":["+data+"]}";

本文转自:https://blog.csdn.net/qq_42290276/article/details/80508332

更多layui知识请关注layui使用教程栏目。

以上就是使用Layui表格实现后台分页的方法的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/35182.html

为您推荐

返回顶部