我常用的分页类


public class Pagination {

/**
*
* @param pageNum
* 当前页数
* @param pageCount
* 总页数
* @param recordCount
* 总记录数
* @param pageUrl
* 页面 URL
* @return
*/
public static String getPagination(int pageNum, int pageCount,
int recordCount, String pageUrl) {

String url = pageUrl.contains("?") ? pageUrl : pageUrl + "?";
if(!url.endsWith("?") && !url.endsWith("&")){
url += "&";
}

StringBuffer buffer = new StringBuffer();
buffer.append("第 " + pageNum + "/" + pageCount + " 页 共 " + recordCount
+ " 记录 ");

buffer.append(pageNum == 1 ? " 第一页 " : " <a href='" + url
+ "pageNum=1'>第一页</a> ");
buffer.append(pageNum == 1 ? " 上一页 " : " <a href='" + url + "pageNum="
+ (pageNum - 1) + "'>上一页</a> ");
buffer.append(pageNum == pageCount ? " 下一页 " : " <a href='" + url
+ "pageNum=" + (pageNum + 1) + "'>下一页</a> ");
buffer.append(pageNum == pageCount ? " 最后一页 " : " <a href='" + url
+ "pageNum=" + pageCount + "'>最后一页</a> ");

buffer.append(" 到 <input type='text' ");
buffer.append(" name='helloweenvsfei_goto_input' ");
buffer.append(" style='width:25px; text-align:center; '> 页 ");
buffer.append(" <input type='button'");
buffer.append(" name='helloweenvsfei_goto_button' value='Go'>");

buffer.append("<script language='javascript'>");
buffer.append("function helloweenvsfei_enter(){");
buffer.append(" if(event.keyCode == 13){");
buffer.append(" helloweenvsfei_goto();");
buffer.append(" return false;");
buffer.append(" }");
buffer.append(" return true;");
buffer.append("} ");
buffer.append("function helloweenvsfei_goto(){");
buffer
.append(" var numText = document.getElementsByName('helloweenvsfei_goto_input')[0].value;");
buffer.append(" var num = parseInt(numText, 10);");
buffer.append(" if(!num){");
buffer.append(" alert('页数必须为数字'); ");
buffer.append(" return;");
buffer.append(" }");
buffer.append(" if(num<1 || num>" + pageCount + "){");
buffer.append(" alert('页数必须大于 1,且小于总页数 " + pageCount + " '); ");
buffer.append(" return;");
buffer.append(" }");
buffer.append(" location='" + url + "pageNum=' + num;");
buffer.append("}");
buffer
.append("document.getElementsByName('helloweenvsfei_goto_input')[0].onkeypress = helloweenvsfei_enter;");
buffer
.append("document.getElementsByName('helloweenvsfei_goto_button')[0].onclick = helloweenvsfei_goto;");
buffer.append("</script>");

return buffer.toString();
}
}



javabean里调用并存session,${pagination}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值