2010寫的一個jsp分頁标簽, 基本能實作任何效果分頁(如谷歌, 百度分頁, AJAX分頁等), 并且能儲存查詢參數, 自認為比較強大, 下面記錄使用方法:
先上一個效果:
1. pagebar.jar加入lib
2. action裡代碼(最少隻需要加入3行代碼):
IConditionHelper helper = ConditionHelper.getInstance(ServletActionContext.getRequest());
UserLstReq userLstReq = new UserLstReq();
userLstReq.setUserName(userName);
userLstReq.setBeginIndex(helper.getBeginIndex());
userLstReq.setPageSize(helper.getPageSize());
helper.getCondition(userLstReq, UserLstReq.class);
UserLstRes res = userService.queryUsers(userLstReq);
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("list", res.getResultLst());
request.setAttribute("page", new BasePageBarBean(helper, res.getCount()));
3. jsp代碼(最好是寫在一jsp裡, 再include友善更改)
<%@ taglib uri="http://www.huiwanpeng.com" prefix="p"%>
<p:pagebar totalRowCount="${page.totalRowCount}" action="${page.action}" pageSize="${page.pageSize}" currentPageNum="${page.currentPageNum}" disableCss="color:green">
總行數#totalRowCount# |
總頁數#totalPageCount# |
目前第#currentPageNum#頁 |
每頁數#pageSize# |
<a onclick="#callFirstPageFun#">第一頁</a>|
<a onclick="#callForePageFun#" style="#forePageDisableCss#">上一頁</a>|
<a onclick="#callNextPageFun#" style="#nextPageDisableCss#">下一頁</a> |
<a onclick="#callLastPageFun#">最後頁</a>
<p:loop positiveStep="2" negativeStep="4" isFill="true" currentPageCss="color:red">
<a style="#currentPageCss#" onclick="#callLoopPageFun#">#currentPageNum# </a>
</p:loop>
<input id="#inputPageNumId#" type="text" style="width:20px"/><input type="button" value="go" onclick="#callGoFun#"/>
</p:pagebar>