1.在pom文件中引入依赖
<!--pagehelper mybatis分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
2.配置application.yml
# 分页插件配置 pagehelper: helperDialect: mysql supportMethodsArguments: true
3.使用分页插件,在查询前使用分页插件,原理:统一拦截sql,为其提供分页功能
/** * page: 第几页 * pageSize: 每页显示条数 */ PageHelper.startPage(page, pageSize);
4.分页数据封装到PagedGridResult.java传给前端
PageInfo<?> pageList = new PageInfo<>(list); PagedGridResult grid = new PagedGridResult(); grid.setPage(page); grid.setRows(list); grid.setTotal(pageList.getPages

最低0.47元/天 解锁文章
5126

被折叠的 条评论
为什么被折叠?



