Spring cloud

Spring boot 整合 PageHelper

2019-01-19  本文已影响96人  Coca_Cola_717b

PageHelper是Mybatis 的一款十分优秀的分页插件,使用此插件可以帮助我们快速的实现分页功能,写过使用limit 分页demo的朋友肯定会觉得分页十分的麻烦,但是使用PageHelper 就可以像spring boot 那样快速分页不用在sql语句中添加limit 就像 spring boot 不用写那么多配置文件一样

第一步 在pom 文件中引入 依赖

<dependency>

  <groupId>com.github.pagehelper</groupId>

  <artifactId>pagehelper-spring-boot-starter</artifactId>

  <version>1.2.10</version>

</dependency>

具体最新版本 可以从 GitHub上找

2.配置yml或者properties

yml格式

pagehelper:

  helperDialect: mysql

  reasonable: true

  supportMethodsArguments: true

  params: count=countSql

因为我使用的是 yml 所以 properties 的配置就贴图上传了

3.最后一步 简单使用分页

导入这个包例如我在service中做分页就在service中导入 strtpage中 第一个是页数 第二个是每页多少内容

然后就可以运行测试了, 注! 这只是一个简单的分页测试 具体还有很多功能可以取官网上找文档

上一篇 下一篇

猜你喜欢

热点阅读