1.引入插件,我用的是gradle
compile group: 'com.github.pagehelper', name: 'pagehelper-spring-boot-starter', version: '1.1.1'
2.正常使用代码
int pageNum = 0;//这里是动态的,为了展示我就写死了
int limit = 10;
PageHelper.startPage(pageNum, limit);
List<YourEntity> list = userMapper.selectByExample(exp);
PageInfo<User> pageInfo = new PageInfo<User>(list);
以上操作正常的分页问题已经得到了解决,如果我们现在要对分页查询出来的list进行转换,如List<User>转换为List<UserTo>,这样问题就来了,构造新的PageInfo对象中是没有分页参数的
针对此问题我手写了一个搬砖的工具类
package com.**.utils;
import com.github.pagehelper.PageInfo;
import java.util.List;
/**
* PageHelper插件对查询出来的原始list转换可以携带分页信息,若对原始数据的list进行了转换,则分页信息就获取不到了
* 为解决上述问题,添加此类
* @param <T>
*/
public class MyPage