上一篇文章介绍了分页插件PageHelper的使用和如何与SpringMVC集成,本文继续讲解一下如何与Spring Boot集成。
集成分页插件的前提是已经配置了Mybatis,关于Spring Boot如何集成Mybatis网上有很多资料,这里就不再赘述了。这里着重介绍分页插件的集成,其实非常简单。
版本说明
- Spring Boot: 1.3.2.RELEASE
- mybatis-spring-boot-starter: 1.1.1
- pagehelper-spring-boot-starter: 1.2.3
Maven依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
配置文件
在Spring Boot配置文件application.properties
中添加:
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
更多配置项可参考前文。
使用
通过以上两项步骤,分页插件已经可以工作了,是不是非常简单!使用方式与之前一模一样:
// startPage(第几页, 多少条数据)
PageHelper.startPage(pageIndex, pageSize);
// Mybatis查询方法
List<InstanceVO> list = instanceDao.select(instance);
// 用PageInfo对结果进行包装
PageInfo pageInfo = new PageInfo(list);
参考
------本文结束 感谢阅读------- 本文作者: cipher
- 本文链接: www.ciphermagic.cn/mybatis-pag…
- 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 CN 许可协议。转载请注明出处!