自己实现了一个分页的小功能,特此记录以备忘:
action中添加上:
int currentPage = 1; int startRow=0; int pageSize = 50; if(request.getParameter("currentPage")!=null){ currentPage=Integer.parseInt(request.getParameter("currentPage")); } if(request.getParameter("pageSize")!=null){ pageSize=Integer.parseInt(request.getParameter("pageSize")); } startRow=(currentPage-1)*pageSize;//查询代码实现……Integer totalRows=value.length; request.setAttribute("currentPage", currentPage); request.setAttribute("totalRows", totalRows); request.setAttribute("totalPages", (totalRows-1)/pageSize+1); request.setAttribute("pageSize", pageSize);
2.jsp部分实现
//处理jsfunction goPage(page,me,total){ var curr = $("#currentPage").val();; if("first"==me){ $("#currentPage").val(1); }else if("next"==me){ $("#currentPage").val(page); }else if("previous"==me){ $("#currentPage").val(page); }else if("last"==me){ $("#currentPage").val(page); } document.forms[0].submit() }//显示
第${currentPage }页 共${totalPages }页 每页${pageSize }条 共${totalRows }条 首页 |