springboot整合mybaits plus 实现分页操作

一  说明

1.1 工程结构

springboot整合mybaits plus 实现分页操作_第1张图片

 工程的搭建参考:springboot 整合mybaits实现crud操作(含分页)案例_健康平安的活着的博客-CSDN博客_springboot使用mybatis进行crud操作

1.2 分页的配置

1.pom的引入

    
    
      com.baomidou
      mybatis-plus
      2.1.8
    
  

2.设置工具类

public class PageUtils implements Serializable {
	private static final long serialVersionUID = 1L;
	//总记录数
	private int totalCount;
	//每页记录数
	private int pageSize;
	//总页数
	private int totalPage;
	//当前页数
	private int currPage;
	//列表数据
	private List list;
	
	//dubbo的函数返回类,含有有参构造函数时,必须写明一个无参构造函数
	public PageUtils() {
		super();
	}

	/**
	 * 分页
	 * @param list        列表数据
	 * @param totalCount  总记录数
	 * @param pageSize    每页记录数
	 * @param currPage    当前页数
	 */
	public PageUtils(List list, int totalCount, int pageSize, int currPage) {
		this.list = list;
		this.totalCount = totalCount;
		this.pageSize = pageSize;
		this.currPage = currPage;
		this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
	}

	/**
	 * 分页
	 */
	public PageUtils(Page page) {
		this.list = page.getRecords();
		this.totalCount = page.getTotal();
		this.pageSize = page.getSize();
		this.currPage = page.getCurrent();
		this.totalPage = page.getPages();
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurrPage() {
		return currPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}
	
}

3.调用类:

3.1 service层

springboot整合mybaits plus 实现分页操作_第2张图片

 4.页面分页效果

springboot整合mybaits plus 实现分页操作_第3张图片

 

你可能感兴趣的:(springboot,spring,boot,java,spring)