关于SpringBoot中mybatis分页插件的使用
PageHelper的作用
在web开发过程中经常会进行数据分页,传统方式是传入分页参数自己进行分页对象组装再进行数据返回,mybatis使用分页插件PageHelper,
可直接根据传入参数使用
PageHelper.startPage(pageNum,pageSize);
自动分页
从而减少了开发分页的工作量
SpringBoot中怎么使用
- 1 在项目中加入PageHelper的依赖jar包,maven工程则pom.xml中加入:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<!-- 特别注意版本问题, 看到评论以后得以纠正 -->
<version>1.2.3</version>
</dependency>
- 2 在application中加入配置
#pagehelper:
#helper-dialect: sqlserver2012
#reasonable: true
#support-methods-arguments: true
#params: count=countSql
- 3 需要进行分页操作的地方加入
PageHelper.startPage(pageNum,pageSize);