侧边栏壁纸
博主头像
阿里灰太狼博主等级

You have to believe in yourself . That's the secret of success.

  • 累计撰写 104 篇文章
  • 累计创建 50 个标签
  • 累计收到 12 条评论

目 录CONTENT

文章目录

Spring Boot 整合 mybatis-pagehelper

阿里灰太狼
2022-02-09 / 0 评论 / 2 点赞 / 245 阅读 / 639 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-02-10,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1.引入分页插件依赖

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

2.配置 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());
grid.setRecords(pageList.getTotal());
2

评论区