码迷,mamicode.com
首页 > 其他好文 > 详细

分页类PageBean的代码

时间:2015-05-14 16:33:56      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:分页   pagebean   javaee   

代码如下:


import java.util.List;

public class PageBean {
	//传递的参数
	private int currentPage;//当前页
	private int pageSize;//每页显示的记录数
	
	//查询数据库
	private int recordCount;//总的记录数
	private List recordList;//本页的数据列表
	
	//计算出来的
	private int pageCount;//总的页数
	private int beginPageIndex;//开始的索引
	private int endPageIndex;//结束的索引
	/**
	 * 只接受4个必要的属性的值,会自动的计算后面的三个属性的值
	 * @param currentPage
	 * @param pageSize
	 * @param recordCount
	 * @param recordList
	 */
	public PageBean(int currentPage, int pageSize, int recordCount,
			List recordList) {
		super();
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.recordCount = recordCount;
		this.recordList = recordList;
		
		//计算pageCount
		//if recordCount pageSize pageCount
		//		10         2         5
		//      11         2         6(5页就不够了)
		pageCount=(recordCount-1)/pageSize+1;
		
		//计算beginPageIndex,endPageIndex
		//a,总的页数不超过10页,就全部显示
		if(pageCount<10){
			beginPageIndex=1;
			endPageIndex=pageCount;
		}else{//b,总的页数超过了10页就显示附近的共10页
			beginPageIndex=currentPage-4;
			endPageIndex=currentPage+5;
			//当前面不足4个页码,就显示前10页(也就是说不足14页)
			if(beginPageIndex<1){
				beginPageIndex=1;
				endPageIndex=10;
			}
			//当最后不足5个页码,就显示后10页
			else if(endPageIndex>pageCount){
				endPageIndex=pageCount;
				beginPageIndex=pageCount-10+1;//(包含两个边界)比如3--12包含3
			}
			
		}
		
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getRecordCount() {
		return recordCount;
	}
	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}
	public List getRecordList() {
		return recordList;
	}
	public void setRecordList(List recordList) {
		this.recordList = recordList;
	}
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	public int getBeginPageIndex() {
		return beginPageIndex;
	}
	public void setBeginPageIndex(int beginPageIndex) {
		this.beginPageIndex = beginPageIndex;
	}
	public int getEndPageIndex() {
		return endPageIndex;
	}
	public void setEndPageIndex(int endPageIndex) {
		this.endPageIndex = endPageIndex;
	}
	
	
}






分页类PageBean的代码

标签:分页   pagebean   javaee   

原文地址:http://blog.csdn.net/u014010769/article/details/45721753

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!