/*
* 创建日期 2005-1-10
* this.url = this.url.replaceAll("(&?start=//d*)|(&?pagesize=//d*)", "");
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
* @author 黄安邦
*/
package com.site.web;
/**
* @author Owner
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class Pager {
private int start = 0; //当前页
private int pageSize = 20; //每页记录数
private int totalRec = 0; //总记录数
private int totalPage = 0; //总页数
private String url = null; //路径
private String description = null;
public Pager(int totalRec, int start, int pageSize, String url) {
this.totalRec = totalRec;
this.pageSize = pageSize;
this.totalPage = this.totalRec % this.pageSize == 0 ? this.totalRec
/ this.pageSize : this.totalRec / this.pageSize + 1;
if (start < 0) {
this.start = 0;
} else if (start > totalRec) {
this.start = (this.totalPage - 1) * pageSize;
} else {
this.start = start;
}
this.url = url;
setDescription();
}
public void setDescription() {
StringBuffer sb = new StringBuffer();
sb.append("每页<b>");
sb.append(this.pageSize + "</b>条记录 |");
sb.append(" 共<b>");
sb.append(this.totalPage + "</b>页/<b>");
sb.append(this.totalRec + "</b>条记录 |");
this.url = this.url.replaceAll("(&?start=//d*)|(&?pagesize=//d*)", "");
if (this.start < this.pageSize) {
sb.append(" 首 页 上一页");
} else {
sb.append(" <a href='").append(this.url).append(
"&start=0&pagesize=").append(this.pageSize).append(
"'>首 页</a>");
sb.append(" <a href='").append(this.url).append(
"&start=").append(this.start - this.pageSize).append(
"&pagesize=").append(this.pageSize).append("'>上一页</a>");
}
if ((this.start >= (this.totalPage - 1) * this.pageSize)
|| (this.totalPage <= 1)) {
sb.append(" 下一页 尾 页");
} else {
sb.append(" <a href='").append(this.url).append(
"&start=").append(this.start + this.pageSize).append(
"&pagesize=").append(this.pageSize).append("'>下一页</a>");
sb.append(" <a href='").append(url).append("&start=")
.append((this.totalPage - 1) * this.pageSize).append(
"&pagesize=").append(this.pageSize).append(
"'>尾 页</a>");
}
sb.append(" | 第<b>" + (this.start / this.pageSize + 1)
+ "</b>页");
this.description = sb.toString();
}
public String getDescription() {
return this.description;
}
public int getStart() {
return this.start;
}
//test
public static void main(String[] args) {
Pager x = new Pager(13, 15, 3,
"http://localhost:8080/members.do?action=list&pagesize=3&start=15");
System.out.println(x.getDescription());
}
}