SQL语句:select * from table limit a,b //从a+1 开始到b
1、写一个Page类
package com.util;
/**
* @author lackiechan
*
*/
public class Page {
private static final int DEFAULT_SIZE=15;//每页默认的大小
private int current;//当前页面
private int total;//总页数
private int allPage;//所有的结果
private int pageSize;//每一页的大小
private Page(){
this.pageSize=DEFAULT_SIZE;
}
public Page(int current,int total){
this.current=current;
this.total=total;
this.pageSize=DEFAULT_SIZE;
this.allPage=(total-1)/pageSize+1;
}
private Page(int current,int total,int pageSize){
this.current=current;
this.total=total;
this.pageSize=pageSize;
this.allPage=(total-1)/pageSize+1;
}
public int getCurrent() {
return current;
}
public void setCurrent(int current) {
this.current = current;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPageSize() {
return pageSize;
}
public void setAllPage(int allPage) {
this.allPage = allPage;
}
public int getAllPage() {
return allPage;
}
}
2.
int p=1;
String indexPage=(String)request.getParameter("page");
if(indexPage==null||"".equals(indexPage)){
p=1;
}
else
p=Integer.parseInt(indexPage);
/***********************获取某页面的人数*****************************/
int totalCount = readerDAO.query(null).size();
Page page = new Page(p, totalCount);
List<ReaderForm> ps = readerDAO.getPersonByPage(p,page);
request.setAttribute("pageReader", ps);
request.setAttribute("page", page);
request.getRequestDispatcher("reader.jsp").forward(request, response);
3、
<td align="center">
<p>
共
<%=currentPage.getTotal()%>
名读者 <span>当前第<%=currentPage.getCurrent()%>页,共<span
id="pages"><%=currentPage.getAllPage()%></span>页 </span>
<%if(currentPage.getCurrent()>1) {%>
<a href="reader?action=readerQuery&page=<%=currentPage.getCurrent()-1%>">上一页</a>
<%} %>
<%if(currentPage.getCurrent()<currentPage.getAllPage()){ %>
<a href="reader?action=readerQuery&page=<%=currentPage.getCurrent()+1%>">下一页</a>
<%} %>
</p>
</td>
5、
String sql="select r.*,t.name as typename,t.number from tb_reader r left join tb_readerType t on r.typeid=t.id limit "
+idmum+" , "+page.getPageSize();