开发J2EE程序的分页类-2

public class CreatePage {

private int currentPage; // 当前页码
private int allP; // 总页数
private int allR; // 总记录数
private String pageLink; // 分页导航栏信息
private String pageInfo; // 分页状态显示信息

public CreatePage() {
currentPage = 1;
allP = 1;
allR = 0;
pageLink = "";
pageInfo = "";
}

/** 设置总记录数 */
public void setAllR(int allR) {
this.allR = allR;
}

/** 计算总页数 */
public void setAllP() {
allP = (allR % Constants.PAGE_MAX_SIZE == 0) ? (allR / Constants.PAGE_MAX_SIZE)
: (allR / Constants.PAGE_MAX_SIZE + 1);
}

/** 设置当前页码 */
public void setCurrentPage(int currentPage) {
if (currentPage < 1)
currentPage = 1;
if (currentPage > allP)
currentPage = allP;
this.currentPage = currentPage;
}

/** 设置分页状态显示信息 */
public void setPageInfo(String action) {
if (allP > 1) {
pageInfo += "每页显示: " + Constants.PAGE_MAX_SIZE + "/" + allR
+ " 条记录.";
pageInfo += "当前页: " + currentPage + "/" + allP + " 页.";

pageInfo += "<form action='" + action + "' method='post'>";
pageInfo += "<input type='text' name='currentPage' class='textInputPage'/>";
pageInfo += "<input type='submit' value='转到'/>";
pageInfo += "</form>";
}
}

/** 设置分页导航栏信息 */
public void setPageLink(String gowhich) {
if (gowhich == null)
gowhich = "";
if (gowhich.indexOf("?") >= 0)
gowhich += "&";
else
gowhich += "?";

if (allP > 1) {

if (currentPage > 1) {
pageLink += "<a href='" + gowhich
+ "currentPage=1'>首页</a> ";
pageLink += "<a href='" + gowhich + "currentPage="
+ (currentPage - 1) + "'>上一页</a> ";
}
if (currentPage < allP) {
pageLink += "<a href='" + gowhich + "currentPage="
+ (currentPage + 1) + "'>下一页</a> ";
pageLink += "<a href='" + gowhich + "currentPage=" + allP
+ "'>尾页</a>";
}
}
}

/** 返回总记录数 */
public int getAllR() {
return allR;
}

/** 返回总页数 */
public int getAllP() {
return allP;
}

/** 返回当前页码 */
public int getcurrentPage() {
return currentPage;
}

/** 返回分页状态显示信息 */
public String getPageInfo() {
return pageInfo;
}

/** 返回分页导航栏信息 */
public String getPageLink() {
return pageLink;
}

public int getCurrentPage() {
return currentPage;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值