mybatis-pagehelper
- 引入分页插件
<!--pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
</dependency>
- 配置yml
# 分页插件配置
pagehelper:
helperDialect: mysql
supportMethodsArguments: true
- 使用分页插件,在查询前使用分页插件,原理:统一拦截sql,为其提供分页功能
PageHelper.startPage(pageNum,pageSIze);
- 分页数据封张到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());
PagedGridResult类
public class PagedGridResult {
private int page; // 当前页数
private int total; // 总页数
private long records; // 总记录数
private List<?> rows; // 每行显示的内容
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public long getRecords() {
return records;
}
public void setRecords(long records) {
this.records = records;
}
public List<?> getRows() {
return rows;
}
public void setRows(List<?> rows) {
this.rows = rows;
}
}