求给分页代码越快越好
分再加

解决方案 »

  1.   

    这好办
    Javabean: 自己改改逻辑处理
    package pageBean;public class Page {
        private int totalPage;//总页数
        private int currentPage;//当前页数
        private int totalRecord;//总的记录条数
        private int currentRecord;//当前记录的条数
        private int pageSize =8;//每页显示的记录数量
    public int getCurrentPage() {
    return currentPage;
    }
    public void setCurrentPage(int currentRecord,int pageSize ) {
            //如果当前记录数除以每页显示条数可以整除,商就是当前的页码
    if(currentRecord%pageSize == 0) 
    {
    currentPage = currentRecord/pageSize;
    }else
    {
               //如果当前记录数除以每页显示条数不能整除,商加1才是当前的页码
    currentPage = currentRecord/pageSize+1;
    }
    }
    public int getCurrentRecord() {
    return currentRecord;
    }
    public void setCurrentRecord(int currentRecord) {
    this.currentRecord = currentRecord;
    }
    public int getPageSize() {
    return pageSize;
    }
    public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
    }
    public int getTotalPage() {
    return totalPage;
    }
    public void setTotalPage(int totalRecord,int pageSize) {
            //如果总记录数除以每页显示条数可以整除,商就是总页码
    if(totalRecord%pageSize == 0) 
    {
    totalPage = totalRecord/pageSize;
    }else
    {
               //如果总记录数除以每页显示条数不能整除,商加1才是总页码
    totalPage = totalRecord/pageSize+1;
    }
    }
    public int getTotalRecord() {
    return totalRecord;
    }
    public void setTotalRecord(int totalRecord) {
    this.totalRecord = totalRecord;
    }
        
    }
    jsp里:<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    <%@ page import="tableBean.TB_newInfo" %>
    <%@ page import="pageBean.Page" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.util.ArrayList" %>
    <jsp:useBean id="db" class="DB.datebasework" scope="page"></jsp:useBean>
    <jsp:useBean id="pager" class="pageBean.Page" scope="page"></jsp:useBean>
    <%--  http://localhost:8081/jspStudentManage/controllerCode/Page.jsp  --%>
    <%-- 从functionCode/seeAboutObject.jsp中获取sql --%>
    <% 
       ArrayList arr=(ArrayList)request.getSession().getAttribute("rsObject");
    %>
    <%
       //从数据库中去出结果集
       int currentRecord = 0;
       pager.setTotalRecord(arr.size());
       pager.setTotalPage(arr.size(),pager.getPageSize());
       //计算并设置分页的参数
       if(request.getParameter("currentRecord")!=null)
       {   
           currentRecord = Integer.parseInt(request.getParameter("currentRecord"));
           pager.setCurrentRecord(currentRecord);
           pager.setCurrentPage(currentRecord,pager.getPageSize());
       }
       
       //从结果集中取出当前页面要显示的记录数
       List<TB_newInfo> subResult = null;
       if(currentRecord==0)
       {
        if(arr.size()<3){//即每页显示数小于ArrayList<student>中的result.size()则不然ArrayindexOutOfBoundsException
          subResult = arr.subList(0,arr.size());
          }else{
           subResult = arr.subList(0,pager.getPageSize());
           }
       }
       if(pager.getCurrentRecord()+pager.getPageSize()<arr.size())
           subResult=arr.subList(pager.getCurrentRecord(),pager.getCurrentRecord()+pager.getPageSize());
       else
           subResult=arr.subList(pager.getCurrentRecord(),arr.size());
     %>
    <html>
      <head>
          <title>查询结果</title>
          
          <script type="text/javascript" src="../JS/tableBS.js"></script>
      </head>
      <body background="/newsReleaseSystem/image/633476704865125559.jpg">
      <fieldset style="width:40%; height:100%" align="center"><legend align="center"><b class="b6" align="center">操作结果</b></legend>
    <br>
    <center>
      <table width="700" border="1" height="82">
          <tr onMouseOver="changColor(this)" onMouseOut="resetColor(this)">
              <td>编号</td>
              <td>类别</td>
              <td>标题</td>
              <td>作者</td>
              <td>状态</td>
              <td>提交时间</td>
              <td>分布时间</td>
         </tr>
         <%
             if(subResult.isEmpty()==false)
             {
                 for(int i=0;i<subResult.size();i++)
                 {
                     TB_newInfo st = subResult.get(i);
                     out.print("<tr onMouseOver=\"changColor(this)\" onMouseOut=\"resetColor(this)\">");
                     out.print("<td>"+st.getNewID()+"</td>");
                     out.print("<td>"+st.getLeiBie()+"</td>");
                     out.print("<td>"+st.getBiaoTi()+"</td>");
                     out.print("<td>"+st.getName()+"</td>");
                     out.print("<td>"+st.getState()+"</td>");
                     out.print("<td>"+st.getTime()+"</td>");
                     out.print("<td>"+st.getTime2()+"</td>");
                     out.print("</tr>");   
                 }    
             }
          %>          
    </table>
    <center>
    <span><font size="2">总<%=pager.getTotalRecord()%>条记录|总<%=pager.getTotalPage()%>页|当前第<%=pager.getCurrentPage()+1%>页|每页<%=pager.getPageSize()%>条|
    <% 
        if(pager.getCurrentRecord()-pager.getPageSize()<0)
            out.println("首页|");
        else
            out.print("<a href='AuditingObjectPage.jsp?currentRecord="+(pager.getCurrentRecord()-pager.getPageSize())+"&pageSize="+pager.getPageSize()+"'>上一页</a>|");
        if(pager.getCurrentRecord()+pager.getPageSize()>pager.getTotalRecord())
            out.println("尾页");
        else
            out.print("<a href='AuditingObjectPage.jsp?currentRecord="+(pager.getCurrentRecord()+pager.getPageSize())+"&pageSize="+pager.getPageSize()+"'>下一页</a>|");  
     %>
    </font></span>
    </center>
    <br><br><center><a href="../controllerCode/newChakan.jsp" target="middle">返回</a></center>
    </center>
    </fieldset>
    </body>
    </html>