1、
PageHelper.startPage()语句要放在查询语句之前,例如这样:
@Override
public Result getPosts(PostsVo postsVo) {
PageHelper.startPage(postsVo.getStart(), postsVo.getLength());
List<PostsDto> postsList = postsMapper.getPosts(postsVo);
return Result.success(new PageInfo<>(postsList));
}
2、
pom文件里要有这两个依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.6</version>
</dependency>