分页

来源:互联网 发布:appstore安装不了软件 编辑:程序博客网 时间:2024/06/05 02:25

以下是jsp中调用上一页和下一页代码

<table align="center">  <tr>    <td align="right">         <a href="javascript:firstPage();">首页</a>         <a href="javascript:prePage();" name="prePage">上一页</a>      <a href="javascript:nextPage();" name="nextPage">下一页</a>    <a href="javascript:lastPage();">尾页</a> pages:    第<a name="curPage" href="javascript:renovate();" ><%=request.getAttribute("curPage").toString() %></a>页/ 共: <%=request.getAttribute("maxRowCount")%> 条/ 共: <%=request.getAttribute("maxPage")%> 页    </td> </tr></table>


在看jsp中被调用function代码

<SCRIPT language=javascript>var rowIndex = 1;function showList(){ //查询document.dataForm.action="<%=request.getContextPath()%>/master!query.action" document.dataForm.submit();}function creatHydm(){ //添加document.dataForm.action="<%=request.getContextPath()%>/master!addpage.action" document.dataForm.submit();}function delHydm(mid){ //删除if(confirm("您确定要删除此记录吗?")){document.dataForm.action="<%=request.getContextPath()%>/master!delete.action?id=${id}&mid="+mid;document.dataForm.submit();}}function firstPage(){ //首页document.dataForm.action ="<%=request.getContextPath()%>/master!queryAllByPage.action?";document.dataForm.submit();}function prePage(){ //前一页var curPage = <%=request.getAttribute("curPage") %>;prePage = curPage -1;if(prePage < 1){alert("已经是首页了");return;}document.dataForm.action ="<%=request.getContextPath()%>/master!queryAllByPage.action?&curPage="+prePage;document.dataForm.submit();}function nextPage(){ //后一页var curPage = <%=Integer.parseInt(request.getAttribute("curPage").toString())%>;var lastPage = <%=Integer.parseInt(request.getAttribute("maxPage").toString())%>;if(curPage >= lastPage){alert("已经是尾页了");return;}var nextPage = curPage + 1;document.dataForm.action ="<%=request.getContextPath()%>/master!queryAllByPage.action?curPage="+nextPage;document.dataForm.submit();}function lastPage(){ //尾页var curPage = <%=Integer.parseInt(request.getAttribute("curPage").toString())%>;var lastPage = <%=Integer.parseInt(request.getAttribute("maxPage").toString())%>;if(curPage >= lastPage){return;}document.dataForm.action ="<%=request.getContextPath()%>/master!queryAllByPage.action?curPage="+lastPage;document.dataForm.submit();}function renovate(){ //刷新document.dataForm.action ="<%=request.getContextPath()%>/master!queryAllByPage.action?&curPage=<%=request.getAttribute("curPage").toString() %>";document.dataForm.submit();}</SCRIPT>

以下是后台处理代码

public String queryAllByPage() throws ClassNotFoundException, SQLException{// 当前页//private int curPage = 1;// 共有多少页//private int maxPage;// 共有多少行//private int maxRowCount; // 每一页有多少行,默认为10行//private int rowsPerPage = 10;System.out.println("当前页:"+curPage);System.out.println("总页数:"+maxPage);System.out.println("总行数:"+maxRowCount);System.out.println("当前页显示:"+rowsPerPage);// 执行查询maxRowCount = masterService.queryCount();System.out.println("共有多少行:"+maxRowCount);maxPage = (this.maxRowCount % this.rowsPerPage == 0) ? this.maxRowCount / this.rowsPerPage : this.maxRowCount / this.rowsPerPage + 1;System.out.println("这是一共多少页:"+maxPage);list = masterService.queryAllByPage(curPage, rowsPerPage);return "query";}

public List<?> queryAllByPage(int curPage,int rowsPerPage) throws ClassNotFoundException, SQLException{// sql语句String sql = "select * from PA_SYS_MASTER LIMIT " + (curPage-1) * rowsPerPage + "," + rowsPerPage;System.out.println("这里是sql:"+sql);// 执行查询return dao.executeQueryForList(sql);}



0 0
原创粉丝点击