今天小编给大家分享的是Layui表格如何实现后台分页,相信很多人都不太了解,为了让大家更加了解Layui,所以给大家总结了以下内容,一起往下看吧。一定会有所收获的哦。
使用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+"]}";
关于Layui表格如何实现后台分页就分享到这里了,希望以上内容可以对大家有一定的参考价值,可以学以致用。如果喜欢本篇文章,不妨把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。