`
gtgt1988
  • 浏览: 111454 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

java 分页类

 
阅读更多

package com.iflytek.hr.model;

public class PageInfo {
	private int pageSize = 30;// 页大小(每页记录数)
	private int currentPage = 0;// 当前页码,从0开始
	private int totalPage;// 总页数

	/**
	 * 使用总的记录条数,创建页面信息对象,默认为30条每页
	 * 
	 * @param totalRowcount
	 */
	public PageInfo(int totalRowCount) {
		this.setTotalPage(totalRowCount);
	}

	/**
	 * 使用指定的页大小和总记录数创建页面信息对象
	 * 
	 * @param pageSize
	 * @param totalRowCount
	 */

	public PageInfo(int pageSize, int totalRowCount) {
		this.pageSize = pageSize;
		this.setTotalPage(totalRowCount);
	}

	/**
	 * 设置页码,从0开始。如果小于第0页则设置为第0页;如果超出最后一页,则设置为最后一页。
	 * 
	 * @param currentPage
	 */
	public void setCurrentPage(int currentPage) {
		if (currentPage < 0) {
			currentPage = 0;
		} else if (currentPage >= totalPage) {
			currentPage = totalPage - 1;
		}
		this.currentPage = currentPage;
	}
	/**
	 * 返回当前页码,从0开始
	 * @return
	 */
	public int getCurrentPage(){
		return this.currentPage;
	}
	/**
	 * 返回总页数
	 * @return
	 */
	public int getTotalPage(){
		return this.totalPage;
	}

	/**
	 * 获得当前页的截止记录数
	 * 
	 * @return
	 */
	public int getPageEndIndex() {
		return (currentPage + 1) * pageSize;
	}

	/**
	 * 获得当前页的起始记录数
	 * 
	 * @return
	 */
	public int getPageStartIndex() {
		return currentPage * pageSize;
	}

	private void setTotalPage(int totalRowCount) {
		this.totalPage = totalRowCount / pageSize;
		if (totalRowCount % pageSize != 0) {// 如果有多余记录,则加1页
			this.totalPage += 1;
		}
	}

}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics