1.引入分页插件依赖

    1. <!--pagehelper -->
    2. <dependency>
    3. <groupId>com.github.pagehelper</groupId>
    4. <artifactId>pagehelper-spring-boot-starter</artifactId>
    5. <version>1.2.12</version>
    6. </dependency>

    2.配置yml

    1. # 分页插件配置
    2. pagehelper:
    3. helperDialect: mysql
    4. supportMethodsArguments: true

    3.使用分页插件,在查询前使用分页插件,原理:统一拦截sql,为其提供分页功能

    1. /**
    2. * page: 第几页
    3. * pageSize: 每页显示条数
    4. */
    5. PageHelper.startPage(page, pageSize);

    4.分页数据封装到PagedGridResult.java传给前端

    1. PageInfo<?> pageList = new PageInfo<>(list);
    2. PagedGridResult grid = new PagedGridResult();
    3. grid.setPage(page);
    4. grid.setRows(list);
    5. grid.setTotal(pageList.getPages());
    6. grid.setRecords(pageList.getTotal());