• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
PHP中文网
帮助109

使用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 "]}";

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanffbbb
系列文章
更多 icon
同类精品
更多 icon
继续加载