导入对pagehelper自动默认配置支持的包pagehelper-spring-boot-starter:
application文件配置com.github.pagehelper pagehelper-spring-boot-starter 1.2.10
测试效果只需要默认的配置就可以了
pagehelper: helper-dialect: mysql #reasonable: true #support-methods-arguments: true #params: count=countSql测试代码
关于userXmlMapper类是使用了代理开发方式的接口类,相关的内容在Mybtis——编写映射配置完成基础增删改查(代理开发方式)
pageInfo可以用来测试你的分页设置是否生效,还有很多属性,就不一一展示了。
@Test
public void testFindAll2(){
PageHelper.startPage(1,2);
List list = userXmlMapper.findAll();
for(User user:list){
System.out.println(user);
}
PageInfo pageInfo = new PageInfo(list,2);
System.out.println("当前页"+pageInfo.getPageNum());
System.out.println("每页显示条数"+ pageInfo.getPageSize());
System.out.println("总条数"+pageInfo.getTotal());
System.out.println("总页数"+pageInfo.getPages());
//......
}
测试结果
pagehelper使用无效的问题
最开始我导入的配置文件
com.github.pagehelper
pagehelper
3.7.5
com.github.jsqlparser
jsqlparser
0.9.1
我在配置都确认无误的情况下,分页依然失效,最开始是根据看的视频教程配的3.7.5的pagehelper和0.9.1的jsqlparser,但是没有效果。
之后又换成了我使用时最新的5.2.1的pagehelper和4.2的jsqlparser,终于能够读取分页结果,但是pageInfo的返回数值跟我设置的数字还是有差异,也就是依然出现错误。
参考了这位老哥的文章spring boot集成pagehelper分页失效问题
才想到直接使用springboot集成好的pagehelper插件。



