<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.6</version>
</dependency>
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageBean <T>{
private Long total;
private List<T> items;
}
@Override
public PageBean<Article> list(Integer pageNum, Integer pageSize, Integer categoryId, String state) {
PageBean<Article> pb = new PageBean<>();
PageHelper.startPage(pageNum,pageSize);
Map<String,Object> map = ThreadLocalUtil.get();
Integer userId = (Integer) map.get("id");
List<Article> list = articleMapper.list(userId,categoryId,state);
Page<Article> page = (Page<Article>) list;
pb.setTotal(page.getTotal());
pb.setItems(page.getResult());
return pb;
}