pagehelper基础使用

匿名 (未验证) 提交于 2019-12-03 00:26:01
pageHelper配置(此配置,当请求页码超过最大页数后,不会返回数据.需要返回的话,配置reasonable=true):
reasonable:分页合理化参数,默认值为falsetruepageNum<=0pageNum>pages(超过总数时),会查询最后一页。默认false
pagehelper.row-bounds-with-count=true pagehelper.support-methods-arguments=true pagehelper.closeConn=false pagehelper.helperDialect=mysql

//特别注意,startPage之后一定要紧跟查询语句,不然可能存在线程安全隐患.具体原因见另外一篇文章

PageHelper.startPage(request.getPageNum(), request.getPageSize());//查询全部时,只需将pageSize置0即可.不过此时得到的总页数是0 List<Invoice> invoiceList = tInvoiceMapper.queryInvoiceList(request);  if (!CollectionUtils.isEmpty(invoiceList)) {     PageInfo<Invoice> pageInfo = new PageInfo<>(invoiceList);      response.setInvoiceList(invoiceList);     response.setPageNum(pageInfo.getPageNum());//获取当前页码     response.setPageSize(pageInfo.getSize());//获取当前页实际结果集个数     response.setTotalPage(pageInfo.getPages());//获取总页数     response.setTotalSize(pageInfo.getTotal());//获取总记录数 }
详细的介绍,请关注github上插件说明点击PageHelper使用文档点击打开pageHelper重要提示Spring Boot 集成 MyBatis, 分页插件 PageHelper, 通用 Mapper


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!