分页工具类

分页类的实现;

参考http://hi.baidu.com/shirdrn/blog/item/03a7887ba4d29df00bd18776.html

相关http://www.cnoug.org/viewthread.php?tid=38

 

package com.victor.util;

import java.util.List;

/**
 * <br>
 * 功能描述: <br>
 * 版权所有: wrs <br>
 * 日期:2009
 * 
 * @author 王汝胜
 * @version 1.0
 */
public class Page {
	private int pageSize = 20; // 每页显示的记录数,默认20条
	private int totalPage; // 页数
	private int rowCount; // 总记录数
	private int currentPage = 1; // 当前页,默认第一页
	private int prePage; // 上一页
	private int nextPage; // 下一页
	private boolean hasNextPage; // 是否有下一页
	private boolean hasPreviousPage; // 是否有前一页
	private int startIndex;// 开始记录索引
	private int endIndex;// 结束记录索引
	private List list;// 可以存放分页数据
	private String sql;//查询数据的sql

	public Page(int rowCount) {
		this.rowCount = rowCount;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public int getNextPage() {
		nextPage = currentPage + 1;
		return nextPage;
	}

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

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPrePage() {
		prePage = currentPage - 1;
		return prePage;
	}

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

	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public int getTotalPage() {
		if (rowCount > pageSize) {
			if (rowCount % pageSize == 0) {
				totalPage = rowCount / pageSize;
			} else {
				totalPage = 1 + (rowCount / pageSize);
			}
		} else {
			totalPage = 1;
		}
		return totalPage;
	}

	public void setTotalPage(int totalPage) {

	}

	public boolean isHasNextPage() {
		boolean flag = true;
		if (currentPage >= totalPage) {// 如果当前页大于等于总页数则没有下一页,下一页链接失效
			flag = false;
		}
		return flag;
	}

	public boolean isHasPreviousPage() {
		boolean flag = true;
		if (currentPage <= 1) {// 如果当前页小于等于1则没有上一页,上一页链接失效
			flag = false;
		}
		return flag;
	}

	public int getStartIndex() {
		startIndex = (currentPage - 1) * pageSize;
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public int getEndIndex() {
		endIndex = currentPage * pageSize;
		return endIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

}

 

你可能感兴趣的:(html,sql,PHP,Blog)