SpringBoot分页插件PageHelper

引入Jar依赖

Springboot的依赖此次省略,pom.xml

		<!-- springboot分页插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.3.0</version>
        </dependency>

yml配置

# 分页配置
pagehelper:
  helper-dialect: mysql
  reasonable: true
  support-methods-arguments: true
  params: count=countSql

Service业务层代码

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Override
    public PageInfo queryUserPage(User user, Page page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<User> userList = userDao.queryList(user);
        return new PageInfo<>(userList);
    }

返回数据:

{
    "total": 5,// 总数
    "list": [
        {
            "queryFields": null,
            "id": 1,
            "userNumber": "001",
            "userName": "admin",
            "password": "123456",
            "realName": null,
            "email": null,
            "mobilePhone": null,
            "identityCard": null,
            "remark": null,
            "photo": null,
            "userType": null,
            "delFlg": null,
            "reversion": null,
            "createdBy": null,
            "createdTime": null,
            "updatedBy": null,
            "updatedTime": null
        },
        {
            "queryFields": null,
            "id": 2,
            "userNumber": "admin",
            "userName": "lagou-user",
            "password": "iuxyzds",
            "realName": null,
            "email": null,
            "mobilePhone": null,
            "identityCard": null,
            "remark": null,
            "photo": null,
            "userType": 0,
            "delFlg": null,
            "reversion": null,
            "createdBy": null,
            "createdTime": null,
            "updatedBy": null,
            "updatedTime": null
        }
    ],
    "pageNum": 1,// 第几页
    "pageSize": 2,// 一页几条
    "size": 2, // 条数
    "startRow": 1, // 从第几行开始
    "endRow": 2, // 搜索到第几行
    "pages": 3, // 总页数
    "prePage": 0,
    "nextPage": 2, // 下一页页码
    "isFirstPage": true,  //是否第一页
    "isLastPage": false, // 是否最后一页
    "hasPreviousPage": false, // 是否有上一页
    "hasNextPage": true, // 是否有下一页
    "navigatePages": 8, // 导航页码数
    "navigatepageNums": [
        1,
        2,
        3
    ],// 所有导航页号
    "navigateFirstPage": 1, // 第一页页码
    "navigateLastPage": 3 // 最后一页页码
}
上一篇:PageHelper使用


下一篇:SpringBoot PageHelper不生效不分页的问题