一个分页类

/**
 * 封装分页信息
 * 
 */
public class Pagination<T> implements Serializable{
	private static final long serialVersionUID = -4263336128482001626L;
	private int total; // 总记录数
	private int pageIndex; // 当前页, 从1开始计数
	private int pageSize; // 页大小
	private List<T> items; // 页数据
	private int startRow; // 起始行, 从1开始计数
	private int endRow; // 结束行, 从1开始计数

	public Pagination() {}
	
	public Pagination(Pagination<T> page) {
		this.pageIndex = page.getPageIndex();
		this.pageSize = page.pageSize;

		this.startRow = pageSize * (pageIndex - 1) + 1;
		this.endRow = this.startRow + pageSize - 1;
	}
	
	public Pagination(int pageIndex, int pageSize) {
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;

		this.startRow = pageSize * (pageIndex - 1) + 1;
		this.endRow = this.startRow + pageSize - 1;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public List<T> getItems() {
		return items;
	}

	public void setItems(List<T> items) {
		this.items = items;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	/**
	 * 起始行位置, 从1开始计数
	 * @return
	 */
	public int getStartRow() {
		return startRow;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	/**
	 * 结束行位置, 从1开始计数
	 * @return
	 */
	public int getEndRow() {
		return endRow;
	}

	public void setEndRow(int endRow) {
		this.endRow = endRow;
	}
}

你可能感兴趣的:(分页 java)