1.添加分页依赖
<!-- springboot分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<!-- 特别注意版本问题, 看到评论以后得以纠正 -->
<version>1.2.3</version>
</dependency>
复制代码
2.配置application.yml
# 分页配置,针对mysql
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
复制代码
3.使用插件
/**
*
* @Title: getList
* @Description: 从数据库中获取所有商品类型列表
* @param pageNum 当前页
* @param pageSize 当前页面展示数目
* @return
* @throws Exception
*/
public List<GoodsType> getList(int pageNum, int pageSize) throws Exception {
//使用分页插件,核心代码就这一行
PageHelper.startPage(pageNum, pageSize);
// 获取
List<GoodsType> typeList = typeDao.getList();
return typeList;
}
复制代码