java分页功能

public class PageUtil
{
	private Collection content;// 存放数据的集合
	private int page;// 当前页数
	private int pageSize;// 每页显示的数据数
	private int total;// 总数据数
	private int totalPages;// 总页数
	private int start;// 开始的数据的下标


	public PageUtil(int page, int pageSize, int total)
	{
		this.page = page;
		this.pageSize = pageSize;
		this.total = total;

		totalPages = (total % pageSize == 0) ? (total / pageSize) : (total
				/ pageSize + 1);
		if (page < 1)
			page = 1;
		if (page > totalPages)
			page = totalPages;
		start = (page - 1) * pageSize;
	}

	public void setContent(Collection content)
	{
		this.content = content;
	}

	public Collection getContent()
	{
		return content;
	}

	public int getPage()
	{
		return page;
	}

	public int getPageSize()
	{
		return pageSize;
	}

	public int getTotal()
	{
		return total;
	}

	public int getTotalPages()
	{
		return totalPages;
	}

	public int getStart()
	{
		return start;
	}
}

 

你可能感兴趣的:(java)