Layui + ssm 分页

男娘i 2022-12-08 05:29 364阅读 0赞

做后台就会涉及到表格数据,当数据多的时候,就要使用分页来显示,这样就显得比较美观。分页确实有效,但它一定会加大系统的复杂度,如果数据量少的话可以不用分页,但是对于企业信息系统来说数据量不会限制在一个小范围内,所以分页还是很有必要的

分页的两个重要参数,一个是一页多少条数据,还有一个就是第几页,从而数据库计算得出显示哪些数据。

那么layui下的分页又有哪些不同呢

Js部分代码

  1. table.render({
  2. elem: '#demo'
  3. ,title:'用户信息'
  4. ,url: '${ctx}/dedicate/list.do' //数据接口
  5. //,contentType: 'application/json'
  6. ,toolbar: '#toolbarDemo'
  7. ,id:'relTable'
  8. ,totalRow:false //合计行
  9. ,page: true //开启分页
  10. ,cols: [[ //表头
  11. //{field: 'numbers', title: '序号', width:80,type:'numbers', fixed: 'left'}
  12. {type:'checkbox',fixed:'left'}
  13. //,{field: 'isCheck', width:80,fixed:'left',templet:setState ,title: '审核否'}
  14. ,{field: 'dedicateLineId',fixed:'left', width:80,hide:true, title: '专线id'}
  15. ,{field: 'dedicateLineName',fixed:'left',width:100, title: '专线名称'}
  16. ,{field: 'dedicateLineAddress', width:100, title: '专线地址'}
  17. ,{field: 'businessLicense', width:100, title: '营业执照'}
  18. ,{field: 'areaId', width:80, title: '地区id'}
  19. ,{field: 'address', width:170, title: '地址'}
  20. ,{field: 'registraionTime', width:170
  21. ,title: '注册时间'}
  22. ,{field: 'describe', width:120, title: '描述'}
  23. ,{field: 'businessLincenseNumber', width:170, title: '营业执照编号'}
  24. ,{field: 'businessLicensePrinted', width:170, title: '营业执照复印件'}
  25. ,{field: 'legalPerson', width:90, title: '法人名称'}
  26. ,{field: 'legalIdCardPrinted',width:170, title: '法人身份证复印件'}
  27. ,{field: 'contactPerson', width:80, title: '联系人'}
  28. ,{field: 'contactNumber', width:170, title: '手机号'}
  29. ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
  30. ]]
  31. ,request:{
  32. pageName:'pageNo',//页码的参数名,默认:page
  33. limitName:'pageSize'//每页数据量的参数名,默认:limit
  34. }
  35. ,limit:10 //每页显示的行数
  36. ,limits:[10,20,30]//每页条数选择项
  37. });

其中pageNo就是第几页,pageSize就是每页显示数据的行数

Mapper

  1. <select id="selectDedivateline" resultMap="BaseResultMap">
  2. SELECT * FROM bm_dedicate_line
  3. <where>
  4. <if test='dedicateLineName !=null and dedicateLineName !=""'>
  5. and dedicate_line_name like CONCAT(CONCAT('%',#{dedicateLineName,jdbcType=VARCHAR},'%'))
  6. </if>
  7. </where>
  8. limit #{start,jdbcType=INTEGER},#{end,jdbcType=INTEGER}
  9. </select>

Impl

  1. @Override
  2. public List<BmDedicateLine> selectDedivateline(Map map,String dedicateLineName) {
  3. // TODO Auto-generated method stub
  4. int pageNo=map.get("pageNo")==null?1:Integer.valueOf(map.get("pageNo")+"");
  5. int pageSize=map.get("pageSize")==null?10:Integer.valueOf(map.get("pageSize")+"");
  6. map.put("start", (pageNo-1)*pageSize);
  7. map.put("end", pageSize);
  8. map.put("dedicateLineName", dedicateLineName);
  9. return dedicateLineDao.selectDedivateline(map);
  10. }

控制器

  1. @ResponseBody
  2. @RequestMapping(value="/list",produces="application/json;charset=UTF-8")
  3. public ResultMap<List<BmDedicateLine>> list(@RequestParam Map map,String dedicateLineName) {
  4. List<BmDedicateLine> emp=iDedicateLineService.selectDedivateline(map,dedicateLineName);
  5. int totalCount=iDedicateLineService.getTotalRow(map);
  6. return new ResultMap<List<BmDedicateLine>>(0,"",totalCount,emp);
  7. }

代码没有很复杂,总之一定要传入两个值,多少条数据和第几页,layui的分页挺好用的。

发表评论

表情:
评论列表 (有 0 条评论,364人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Layui + ssm

    做后台就会涉及到表格数据,当数据多的时候,就要使用分页来显示,这样就显得比较美观。分页确实有效,但它一定会加大系统的复杂度,如果数据量少的话可以不用分页,但是对于企业信息系统来

    相关 javaweb--layui表格

    本文最好是有一定javaweb 基础的人查看,你知道,一些最简单的jdbc的实际操作(CRUD) 如何写出以待用.css,.js的外部模板的jsp页面;   使用最基础的

    相关 ssm查询

    引言:基于ssm框架下,利用Mybaits插件PageHelper进行分页查询,可以省去大量繁琐的代码,操作起来更为方便, 1、数据库表的设计 ![70][] ---