package org.xiosu.multipages.util;
/**
*
*/
public class MultiPagesBean {
//总行数
private int rowsTotal = 0;
//每页的行数
private int rowsPerPage = 0;
//要显示的页面
private int currentPage = 0;
//超链接,型如"http://localhost:8080/multiPages/mainservlet?"
private String url = "";
/**
*
*/
public MultiPagesBean(int rowsCount, int rowsPerPage, int currentPage,
String url) {
this.rowsTotal = rowsCount;
this.rowsPerPage = rowsPerPage;
this.currentPage = currentPage;
this.url = url;
}
/**
* 返回分页条内容
*/
public String getPageBar() {
// 总页数
int pageCount = (rowsTotal + rowsPerPage - 1) / rowsPerPage;
// 分页条的内容
StringBuffer strResult = new StringBuffer();
if (currentPage < 1) {
strResult.append("请求的页数小于一!");
}
if (currentPage == 1) {
strResult.append(" <a href=" + url
+ "requestPage=2>下一页</a> <a href=" + url + "requestPage="
+ pageCount + ">尾页<a> ");
} else {
if (currentPage < pageCount) {
strResult.append(" <a href=" + url
+ "requestPage=1>首页</a> <a href=" + url
+ "requestPage=" + (currentPage - 1)
+ ">上一页</a> <a href=" + url + "requestPage="
+ (currentPage + 1) + ">下一页</a> <a href=" + url
+ "requestPage=" + pageCount + ">尾页<a> ");
}
if (currentPage == pageCount) {
strResult.append(" <a href=" + url
+ "requestPage=1>首页</a> <a href=" + url
+ "requestPage=" + (currentPage - 1) + ">上一页</a> ");
}
if (currentPage > pageCount) {
strResult.append("请求页数大于总页数!");
}
}
strResult.append("<br/>( " + currentPage + "/" + pageCount + ", 共"
+ rowsTotal + "条记录, 每页最多" + rowsPerPage + "条 )");
return strResult.toString();
}
}