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;
}