MyBatis 分页查询

实现步骤

  1. 通过扩展Mapper实现分页查询:
  2. 为Mapper.xml搜索节点
  3. 为Mapper.class 添加对应的搜索方法

1 BasePage分类



/**
 * 分页工具类
 */
public class BasePage {
    protected Integer page;
    protected Integer pageSize;
    protected Integer skip;
    protected Integer totalPage;
    protected Integer totalSize;
    
    public Integer getPage() {
        return page;
    }
    public void setPage(Integer page) {
        this.page = page;
    }
    public Integer getPageSize() {
        return pageSize;
    }
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
    public Integer getSkip() {
        return (page-1)*pageSize;
    }
    public void setSkip(Integer skip) {
        this.skip = skip;
    }
    public Integer getTotalPage() {
        return (this.totalSize - 1) / this.pageSize + 1;
    }
    public Integer getTotalSize() {
        return totalSize;
    }
    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }
    public void setTotalSize(Integer totalSize) {
        this.totalSize = totalSize;
    }
    
}


2 搜索节点示例


 


3 Mapper 方法名


 List selectPageByExample(OrderExample example);

4 使用案例片段


                        example.setPage(basePage.getPage());
            example.setPageSize(basePage.getPageSize());
            example.setOrderByClause("exam_number asc");

            list = this.mapper.selectPageByExample(example);

你可能感兴趣的:(MyBatis 分页查询)