J2EE分页,PageUtil

package com.tnt.util;

public class PageUtil {
	private int currentPage;// 当前页
	private int pageSize = 10;// 每页显示记录数 常量
	private int totalRecord;// 总记录数
	private int totalPage;// 总页数
	private int firstPage;// 第一页
	private int lastPage;// 最后一页
	private int prePage;// 上一页
	private int nextPage;// 下一页
	private int position;// 从第几条信息记录 开始查询
//	private Properties properties;

//	public void initPageSize() {
//		properties = new Properties();
//		InputStream loadFile = this.getClass().getResourceAsStream(
//				"/com/dada/config/conn.properties");
//		try {
//			properties.load(loadFile);
//
//			// 从配置文件读取 每页显示记录数 常量
//			pageSize = Integer.parseInt(properties.getProperty("pageSize")
//					.trim());
//			System.out.println("pagesize:" + pageSize);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}

	public PageUtil(int totalRecord) {
//		initPageSize();// 一定放在此构造方法的第一行
		this.totalRecord = totalRecord;
	}

	public PageUtil(int currentPage, int totalRecord) {
//		initPageSize();// 一定放在此构造方法的第一行
		this.totalRecord = totalRecord;
		this.currentPage = currentPage;
		// initPageSize();
	}

	public int getCurrentPage() {
		if (this.currentPage < 1)
			this.currentPage = 1;
		if (this.currentPage > this.getTotalPage())
			this.currentPage = this.getTotalPage();

		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 getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public int getTotalPage() {
		if (this.getTotalRecord() % pageSize == 0)
			return this.getTotalRecord() / pageSize;
		return this.getTotalRecord() / pageSize + 1;
	}

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

	public int getFirstPage() {
		return 1;
	}

	public void setFirstPage(int firstPage) {
		this.firstPage = firstPage;
	}

	public int getLastPage() {
		return this.getTotalPage();
	}

	public void setLastPage(int lastPage) {
		this.lastPage = lastPage;
	}

	public int getPrePage() {
		if (this.getCurrentPage() - 1 <= 0)
			return 1;
		return this.getCurrentPage() - 1;
	}

	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}

	public int getNextPage() {
		if (this.getCurrentPage() + 1 >= this.getTotalPage())
			return this.getTotalPage();
		return this.getCurrentPage() + 1;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public int getPosition() {
		return (this.getCurrentPage() - 1) * pageSize + 1;
	}

	public void setPosition(int position) {
		this.position = position;
	}
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值