Import dependence

<! <dependency> <groupId>com.github. Pagehelper </groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2. 5</version> </dependency> <! -- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.14.</version>
</dependency>
Copy the code

The configuration file

Pagehelper: helper-dialect: mysql # whether to enable paging rationalization. If enabled, when pagenum<1When pagenum> Pages, the system automatically queries data on the first page. When pagenum> Pages, the system automatically queries data on the last page. If not enabled, both cases return blank data for reasonable:false# the default valuefalseThe paging plug-in will automatically paginate the query method based on the values of the params configuration fields above. support-methods-arguments:true
  params:
Copy the code

Note: with a reasonable value of true, if there is no data on the next page, return data on the previous page; if false, return null if there is no data on the current page.

use

@Override
public MyResult getAll(int pageNo,int pageSize) {
    PageHelper.startPage(pageNo,pageSize);
    PageInfo pageInfo = new PageInfo(articleDao.getAll());
    return MyResult.success(pageInfo);
}
Copy the code

The results of

Reference documentation

SpringBoot2.0 uses pagehelper for paging queries