欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java分页类

程序员文章站 2024-02-20 15:37:16
...
public class Pagination<T> {

	private PageParam pageParam;
	private List<T> list;
	
	public Pagination() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Pagination(PageParam pageParam, List<T> list) {
		super();
		this.pageParam = pageParam;
		this.list = list;
	}
	public PageParam getPageParam() {
		return pageParam;
	}
	public void setPageParam(PageParam pageParam) {
		this.pageParam = pageParam;
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}	
	
}

 

    

public class PageParam {

	private int pageFirst = 0;
	private int pageNum = 1;
	private int pageSize = 10;
	private int totalCount = 0;
	private int totalPage = 0;
	
	public PageParam(int pageNum, int pageSize, int totalCount, int totalPage) {
		super();
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		this.totalCount = totalCount;
		this.totalPage = totalPage;
	}
	public PageParam() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	public int getPageFirst() {
		return pageFirst;
	}
	public void setPageFirst(int pageFirst) {
		this.pageFirst = pageFirst;
	}
	public int getPageNum() {
		return pageNum;
	}
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
}

 

   

public class PageUtil {

	public static PageParam get(int pageNum,int pageSize){
		PageParam p = new PageParam();
		int pageFirst = (pageNum-1)*pageSize;
		p.setPageFirst(pageFirst);
		p.setPageNum(pageNum);
		p.setPageSize(pageSize);
		return p;
	}
	public static PageParam get(int pageNum,int pageSize,int totalCount){
		int pageFirst = (pageNum-1)*pageSize;
		int totalPage = (totalCount-1)/pageSize+1;
		PageParam p = new PageParam();
		p.setPageFirst(pageFirst);
		p.setPageNum(pageNum);
		p.setPageSize(pageSize);
		p.setTotalCount(totalCount);
		p.setTotalPage(totalPage);
		return p;
	}
}

 

相关标签: page java