分页工具类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();
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值