🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] #### pom.xml引入 ~~~ <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.6</version> </dependency> ~~~ #### 分页包装类 ~~~ package com.blog.util; import com.github.pagehelper.PageInfo; import lombok.Data; import java.util.List; @Data public class PageWrap<T extends List>{ private T data; private int pageSize; private int totalPage; private int recordCount; public PageWrap() { } public PageWrap(T t, int recordCount, int pageSize) { this.data = t; this.recordCount = recordCount; this.pageSize = pageSize; this.totalPage = computeTotalPage(recordCount, pageSize); } public static int computeTotalPage(int recordCount, int pageSize) { if (recordCount % pageSize == 0) { return recordCount / pageSize; } else { return recordCount / pageSize + 1; } } public static <T extends List> PageWrap<T> createPageWrap(T data, int recordCount, int pageSize) { return new PageWrap<T>(data, recordCount, pageSize); } public static <T extends List> PageWrap<T> createPageWrap(T data, int pageSize) { PageInfo pageInfo = new PageInfo(data); return new PageWrap<T>(data, (int) pageInfo.getTotal(), pageSize); } } ~~~ service ~~~ public interface ArticleService { PageWrap<List<Article>> getALLArticel(Integer is_hot); } ~~~ #### 实现类 ~~~ @Service public class ArticleImpl implements ArticleService { @Autowired private ArticleMapper articleMapper; /** * @desc: 获取文章列表 * @author: cfun * @date: 2019-11-08 **/ @Override public PageWrap<List<Article>> getALLArticel(Integer is_hot) { //判断账号是否已经存在 List<Article> articleList = articleMapper.selectByExampleWithBLOBs(is_hot); return PageWrap.createPageWrap(articleList,1,10); } } ~~~