springboot业务功能实战(二)pagehelper分页插件使用详解

举报
小鲍侃java 发表于 2021/09/09 23:53:58 2021/09/09
【摘要】 1.pom文件 <!--pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelp...

1.pom文件


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

2.application.xml

本项目数据库为oracle


  
  1. # PageHelper分页插件
  2. pagehelper:
  3. helperDialect: oracle
  4. reasonable: true
  5. supportMethodsArguments: true
  6. params: count=countSql

3.使用


  
  1. public Result<*>(*VO *VO) {
  2. Result<*> resultVO = new Result<>();
  3. // 分页
  4. Page page = new Page();
  5. if (!CommonUtil.isEmpty(*VO.getPageNum()) && !CommonUtil.isEmpty(*VO.getPageSize())) {
  6. page = PageHelper.startPage(*VO.getPageNum(), *VO.getPageSize());
  7. resultVO.setPageNum(*VO.getPageNum());
  8. resultVO.setPageSize(*VO.getPageSize());
  9. }
  10. // ASC是根据id 正向排序,DESC是反向排序
  11. if (!CommonUtil.isEmpty(*VO.getOrder())) {
  12. PageHelper.orderBy(*VO.getOrder());
  13. }
  14. // 业务查询 只有这一句是业务查询!!!
  15. List<*VO> result = *Service.query(*VO);
  16. // 分页总数封装
  17. Long total = page.getTotal();
  18. resultVO.setTotal(total);
  19. // 实体封装
  20. resultVO.setData(result );
  21. return resultVO;
  22. }

注意:Result实体类和输入实体都需要继承BaseEntity

public class *VO extends BaseEntity
 

  
  1. public class BaseEntity {
  2. /**
  3. * 页码
  4. */
  5. private Integer pageNum;
  6. /**
  7. * 条数
  8. */
  9. private Integer pageSize;
  10. /**
  11. * 返回总数
  12. */
  13. private Long total;
  14. /**
  15. * 排序字段
  16. */
  17. private String order;
  18. /**
  19. * 数据权限
  20. */
  21. private String dataScope;
  22. }

文章来源: baocl.blog.csdn.net,作者:小黄鸡1992,版权归原作者所有,如需转载,请联系作者。

原文链接:baocl.blog.csdn.net/article/details/106048390

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。