添加pageHelper依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>
在yml 或者properties里配置
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
在需要分页的地方加上参数:第几页和每页多少条数据
public List<Notice> list(@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum
@RequestParam(defaultValue = "2",value = "pageSize"){
PageHelper.startPage(pageNum,pageSize);
List<Notice> listNotice =noticeService.list();
return listNotice;
}