PageHelper分页插件

在使用PageHelper分页插件时要先添加PageHelper依赖

         
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.3.1
        

PageHelper类调用父类的startPage()方法并传参,获取Page对象。可以通过此对象获得总记录数。
Page对象内部的属性:

public class Page extends ArrayList implements Closeable {
    private static final long serialVersionUID = 1L;
    private int pageNum;
    private int pageSize;
    private long startRow;
    private long endRow;
    private long total;
    private int pages;
    private boolean count;
    private Boolean reasonable;
    private Boolean pageSizeZero;
    private String countColumn;
    private String orderBy;
    private boolean orderByOnly;
    private BoundSqlInterceptor boundSqlInterceptor;
    private transient Chain chain;

PageHelper分页插件具体使用如下:

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserDao sysUserDao;

    @Override
    public PageObject findPageObjects(String username, Integer pageCurrent) {
        int pageSize = 5;
        Page page = PageHelper.startPage(pageCurrent, pageSize);
        Listrecords=sysUserDao.findPageObjects(username);
        long rowCount= page.getTotal();
        return new PageObject<>((int)rowCount,records,pageCurrent,pageSize);

    }
} 
 

问题分析:
在springboot项目中引入

         
            com.github.pagehelper
            pagehelper
            5.2.0
        

发现分页没生效

解决办法:发现SpringBoot项目依赖的分页插件和Spring项目有所不同,需要spring-boot-starter下的包才可以。

你可能感兴趣的:(PageHelper分页插件)