分页
简介
基于 PageHelper 实现分页, PageHelper 是一个 MyBatis 分页插件,支持多种数据库,用法简单,而且完全不依赖任何第三方组件。
依赖
在 tang-commons/pom.xml 中声明依赖 pagehelper-spring-boot-starter,详情可查看 pagehelper-spring-boot-starter
xml
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>使用
- 返回类型为
PageResult,PageResult为分页结果集,包含分页信息和数据列表 - 使用
PageUtils.startPage()开启分页,PageUtils.startPage()会自动获取分页参数,分页参数为pageNum和pageSize,分页参数默认值为pageNum = 1和pageSize = 10 - 使用
PageUtils.getDataTable(list)获取分页结果集,list为分页数据列表
java
@GetMapping("/list")
public PageResult list(Custom custom){
PageUtils.startPage();
var list = customService.selectCustomList(custom);
return PageUtils.getDataTable(list);
}