springboot业务功能实战(二)pagehelper分页插件使用详解
【摘要】
1.pom文件
<!--pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelp...
1.pom文件
-
<!--pagehelper -->
-
<dependency>
-
<groupId>com.github.pagehelper</groupId>
-
<artifactId>pagehelper-spring-boot-starter</artifactId>
-
<version>1.2.5</version>
-
</dependency>
2.application.xml
本项目数据库为oracle
-
# PageHelper分页插件
-
pagehelper:
-
helperDialect: oracle
-
reasonable: true
-
supportMethodsArguments: true
-
params: count=countSql
3.使用
-
public Result<*>(*VO *VO) {
-
Result<*> resultVO = new Result<>();
-
// 分页
-
Page page = new Page();
-
if (!CommonUtil.isEmpty(*VO.getPageNum()) && !CommonUtil.isEmpty(*VO.getPageSize())) {
-
page = PageHelper.startPage(*VO.getPageNum(), *VO.getPageSize());
-
resultVO.setPageNum(*VO.getPageNum());
-
resultVO.setPageSize(*VO.getPageSize());
-
}
-
// ASC是根据id 正向排序,DESC是反向排序
-
if (!CommonUtil.isEmpty(*VO.getOrder())) {
-
PageHelper.orderBy(*VO.getOrder());
-
}
-
// 业务查询 只有这一句是业务查询!!!
-
List<*VO> result = *Service.query(*VO);
-
// 分页总数封装
-
Long total = page.getTotal();
-
resultVO.setTotal(total);
-
// 实体封装
-
resultVO.setData(result );
-
return resultVO;
-
}
注意:Result实体类和输入实体都需要继承BaseEntity
public class *VO extends BaseEntity
-
public class BaseEntity {
-
-
/**
-
* 页码
-
*/
-
private Integer pageNum;
-
-
/**
-
* 条数
-
*/
-
private Integer pageSize;
-
-
/**
-
* 返回总数
-
*/
-
private Long total;
-
-
/**
-
* 排序字段
-
*/
-
private String order;
-
-
/**
-
* 数据权限
-
*/
-
private String dataScope;
-
}
文章来源: baocl.blog.csdn.net,作者:小黄鸡1992,版权归原作者所有,如需转载,请联系作者。
原文链接:baocl.blog.csdn.net/article/details/106048390
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)