1. 依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
2.service层
- 只有紧跟着PageHelper.startPage(pageNum,pageSize)的sql语句才被pagehelper起作用
@Override
public List<Article> listArticles(int pageNum, int pageSize) {
PageHelper.startPage(pageNum,pageSize);
List<Article> list = articleMapper.listArticles();
PageInfo<Article> pageInfo = new PageInfo<>(list);
return pageInfo.getList();
}
3.controller层
List<Article> articles = articleService.listArticles(pageNum,pageSize);