关于git:MyBatis-分页插件-PageHelper

30次阅读

共计 1331 个字符,预计需要花费 4 分钟才能阅读完成。

在应用 PageHelper 分页插件时要先增加 PageHelper 依赖

         <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>

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

public class Page<E> extends ArrayList<E> 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<SysUser> findPageObjects(String username, Integer pageCurrent) {
        int pageSize = 5;
        Page<Object> page = PageHelper.startPage(pageCurrent, pageSize);
        List<SysUser>records=sysUserDao.findPageObjects(username);
        long rowCount= page.getTotal();
        return new PageObject<>((int)rowCount,records,pageCurrent,pageSize);

    }
}

问题剖析:
在 springboot 我的项目中引入

         <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.2.0</version>
        </dependency>

发现分页没失效

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

正文完
 0