JAVA分頁總結

JAVA分頁總結前端

環境:數據庫用的是MYSQLsql

 

不走1:前端頁面增長「上一頁,下一頁」……數據庫

 

<ahref="?startindex=&lt;%=preindex%>&amp;pagesize=10"&gt;上一頁</a>後端

 

<ahref="?startindex=&lt;%=nextindex%>&amp;pagesize=10"&gt;下一頁</a>ide

 

 

不走2JSP頁面增長代碼spa

recordop c=   new recordop();索引

c.request=request;get

ResultSet rs=c.list("uname");     //取得查詢紀錄it

Stringpreindex=c.getpreindex();class

String nextindex=c.getnextindex();

 

 

 

不走3:後端JAVA增長如下3個方法用來計算上一頁及下一頁索引

 

publicintpagesize=12;

    public String getpreindex()

    {

       int curindex=0;

       if(request.getParameter("startindex")==null)

           return"0";

       else

       {

           curindex=Integer.valueOf(request.getParameter("startindex"));

           int pre=curindex-pagesize;

           if(pre&lt;0)

              return"0";

           else

              return String.valueOf(pre);

          

       }

      

      

    }

    public String getCurIndex()

    {

       int curindex=0;

       if(request.getParameter("startindex")==null)

           return"0";

       else

       {

           return (request.getParameter("startindex"));

            

          

       }

      

      

    }

   

    public Stringgetnextindex()

    {

       int curindex=0;

       if(request.getParameter("startindex")==null)

       {

           int next=curindex&#43;pagesize;

           return String.valueOf(next);

       }

            

       else

       {

           curindex=Integer.valueOf(request.getParameter("startindex"));

           int next=curindex&#43;pagesize;        

           return String.valueOf(next);

          

       }

    }

 

 

不走4:增長LIST方法,查詢紀錄:主要語句爲

 

 

    String sql = "select *from vinrecord order by id desc limit "&#43;getCurIndex()&#43;","&#43;String.valueOf(pagesize);

相關文章
相關標籤/搜索