天天看點

萬能分頁标簽

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>