分页工具类Pager

package com.rzy.api;

public class Pager
{
	private int currPage = 1;
	private int pageSize = 10;
	private int pageCount;
	private int count = 0;
	private String url;
	private String tagBg = "#fff url(aaa.gif)";
	private String tagColor = "#000";

	public Pager(int count, int currPage, int pageSize, String url)
	{
		this.count = count;
		this.currPage = currPage;
		this.pageSize = pageSize;
		this.pageCount = count % pageSize == 0 ? (count / pageSize)
				: (count / pageSize) + 1;
		this.url = url;
	}

	public String getTag()
	{
		StringBuffer sb = new StringBuffer();
		sb
				.append(String
						.format(
								"<div style='padding: 5px 30px;margin:0;height:25px;background:%s'>",
								this.tagBg));
		if (this.count == 0)
		{
			sb.append("没有数据");
		}
		else
		{
			sb.append(String.format("总记录%d条&nbsp;&nbsp;当前第%d/%d页", this.count,
					this.currPage, this.pageCount));
			sb.append("&nbsp;&nbsp;&nbsp;&nbsp;");
			String tpl = "<a href=%s&currPage=%d&pageSize=%d style='color:%s'>%s</a>&nbsp;&nbsp;";
			String first = "";
			if (this.currPage != 1)
			{
				first = String.format(tpl, this.url, 1, this.pageSize,
						this.tagColor, "首页");
			}
			String pre = "";
			if (this.currPage > 1 && this.currPage <= this.pageCount)
			{
				pre = String.format(tpl, this.url, this.currPage - 1,
						this.pageSize, this.tagColor, "上一页");
			}
			String next = "";
			if (this.currPage >= 1 && this.currPage < this.pageCount)
			{
				next = String.format(tpl, this.url, this.currPage + 1,
						this.pageSize, this.tagColor, "下一页");
			}
			String last = "";
			if (this.currPage != this.pageCount)
			{
				last = String.format(tpl, this.url, this.pageCount,
						this.pageSize, this.tagColor, "尾页");
			}
			sb.append(first);
			sb.append(pre);
			sb.append(next);
			sb.append(last);
			sb.append("</div>");
		}
		return sb.toString();
	}
}

 

你可能感兴趣的:(PAGER)