目录
导包
<!-- PageHelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.0</version>
</dependency>
yml配置
#pagehelper分页插件配置
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
上手
@Test
void queryList(){
PageHelper.startPage(1, 3);
//service自定义方法
List<ArticlePicture> picUrl = pictureService.getPicIndex();
// 将查到的集合封装到 PageInfo 对象中
PageInfo<ArticlePicture> PageInfo = new PageInfo<ArticlePicture>(picUrl);
System.out.println(PageInfo);
}
结果
PageInfo{pageNum=1, pageSize=3, size=3, startRow=1, endRow=3, total=5, pages=2, list=Page{count=true, pageNum=1, pageSize=3, startRow=0, endRow=3, total=5, pages=2, reasonable=true, pageSizeZero=false}[ArticlePicture(pkId=null, picName=null, url=http://localhost:20219/img/index/50_content_1579597857373938.png, articleId=null), ArticlePicture(pkId=null, picName=null, url=http://localhost:20219/img/index/50_content_1579597857373934.png, articleId=null), ArticlePicture(pkId=null, picName=null, url=http://localhost:20219/img/index/50_content_1579597857373937.png, articleId=null)], prePage=0, nextPage=2, isFirstPage=true, isLastPage=false, hasPreviousPage=false, hasNextPage=true, navigatePages=8, navigateFirstPage=1, navigateLastPage=2, navigatepageNums=[1, 2]}
参数表达:
/**
* 当前页
*/
private int pageNum;
/**
* 每页的数量
*/
private int pageSize;
/**
* 当前页的数量
*/
private int size;
/**
* 由于startRow和endRow不常用,这里说个具体的用法
* 可以在页面中"显示startRow到endRow 共size条数据"
* 当前页面第一个元素在数据库中的行号
*/
private long startRow;
/**
* 当前页面最后一个元素在数据库中的行号
*/
private long endRow;
/**
* 总页数
*/
private int pages;
/**
* 前一页
*/
private int prePage;
/**
* 下一页
*/
private int nextPage;
/**
* 是否为第一页
*/
private boolean isFirstPage = false;
/**
* 是否为最后一页
*/
private boolean isLastPage = false;
/**
* 是否有前一页
*/
private boolean hasPreviousPage = false;
/**
* 是否有下一页
*/
private boolean hasNextPage = false;
/**
* 导航页码数
*/
private int navigatePages;
/**
* 所有导航页号
*/
private int[] navigatepageNums;
/**
* 导航条上的第一页
*/
private int navigateFirstPage;
/**
* 导航条上的最后一页
*/
private int navigateLastPage;