springboot项目分页查询

(1)添加依赖

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.3</version>
</dependency>

(2)具体思想

①声明一个类PageRequest,这个类含有当前页码(pageNum)和每页数量(pageSize)两个参数;

②controller向service传递PageRequest类;

springboot项目分页查询

③service获取当前页码(pageNum)和每页数量(pageSize)两个参数,并通过PageHelper.startPage(int pageNum,int pageSize)设置分页,再查询,最后返回带页码的参数。

springboot项目分页查询

另外,可以尝试二次封装:

①接上面的步骤:

②声明一个PageResult类,这个类有你想要的参数;

springboot项目分页查询

(注意修改方法的返回类型)

springboot项目分页查询