java分页工具

编程知识 行业动态 更新时间:2024-06-13 00:21:18
import java.util.List;
 
public class Page {
	//当前页:
	private int currentPage;
	//上一页:
	private int prePage;
	//下一页:
	private int nextPage;
	//总页数:
	private int totalPage;
	//每页记录数:
	private int pageSize;
	//总记录数据:
	private int totalRecords;
	//开始记录索引:
	private int startIndex;
	
	private List<? extends Object> records;
	
	
 
	public List<? extends Object> getRecords() {
		return records;
	}
	public void setRecords(List<? extends Object> records) {
		this.records = records;
	}

	/**
	 * @param currentPage	当前页
	 * @param totalRecords	总记录数
	 * @param pageSize		每页数量
	 */
	public Page(int currentPage, int totalRecords, int pageSize) {
		super();
		this.currentPage = currentPage;
		this.totalRecords = totalRecords;
		if(pageSize == 0 || pageSize>50) {
			pageSize = 10;
		}
		this.pageSize = pageSize;
		//开始记录索引
		this.startIndex = (currentPage-1)*pageSize;
		//总页数:
		this.totalPage = totalRecords%pageSize==0 ? totalRecords/pageSize:totalRecords/pageSize+1;
		
	}
	/**
	 * 
	 * @param currentPage 当前页
	 * @param totalRecords 总记录数
	 */
	public Page(int currentPage, int totalRecords) {
		this(currentPage, totalRecords, 0);
	}
 
	//上一页
	public int getPrePage() {
		prePage = currentPage==1?currentPage:currentPage-1;
		return prePage;
	}
 
	//下一页
	public int getNextPage() {
		nextPage = currentPage==totalPage?totalPage:currentPage+1;
		return nextPage;
	}
 
	public int getCurrentPage() {
		return currentPage;
	}
 
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
 
	public int getTotalPage() {
		return totalPage;
	}
 
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
 
	public int getPageSize() {
		return pageSize;
	}
 
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
 
	public int getTotalRecords() {
		return totalRecords;
	}
 
	public void setTotalRecords(int totalRecords) {
		this.totalRecords = totalRecords;
	}
 
	public int getStartIndex() {
		return startIndex;
	}
 
	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}
 
	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}
 
	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}
	
	
	
	
}

更多推荐

java分页工具

本文发布于:2023-03-31 14:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/9009fa80b74f58a0ea8b881ea0ecf561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   工具   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!