JAVA分頁總結前端
環境:數據庫用的是MYSQLsql
不走1:前端頁面增長「上一頁,下一頁」……數據庫
<ahref="?startindex=<%=preindex%>&pagesize=10">上一頁</a>後端
<ahref="?startindex=<%=nextindex%>&pagesize=10">下一頁</a>ide
不走2:JSP頁面增長代碼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<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+pagesize;
return String.valueOf(next);
}
else
{
curindex=Integer.valueOf(request.getParameter("startindex"));
int next=curindex+pagesize;
return String.valueOf(next);
}
}
不走4:增長LIST方法,查詢紀錄:主要語句爲
String sql = "select *from vinrecord order by id desc limit "+getCurIndex()+","+String.valueOf(pagesize);