三个条件
1.总共多少条记录
2.每页多少条
3.请求第几页
SQL
oracle:
select * from (select c.*,rownum r from category c) where r>=11 and r<=15
分页信息封装一个类PageInfo
package com.page;
public class PageInfo {
// 1,总记录条数
// 2,一页显示多少条
// 3,请求页码
private int totalPageCount;//总页数
private int currentPageCount = 5;
private int requestPage = 1;
// begin =(requestPage-1)*currentPageCount+1;
// end =requestPage*currentPageCount;
private int begin;
private int end;
private int totalRecordCount;//总记录条数
private int previousPage;//上一页
private int nextPage;//下一页
public int getTotalRecordCount() {
return totalRecordCount;
}
public void setTotalRecordCount(int totalRecordCount) {
this.totalRecordCount = totalRecordCount;
}
public int getPreviousPage() {
return previousPage=requestPage>1?(requestPage-1):1;
}
public int getNextPage() {
int total = getTotalPageCount();
return nextPage=requestPage<total?(requestPage+1):total;
}
public PageInfo(int requestPage) {
this.requestPage = requestPage;
this.begin = (requestPage - 1) * this.currentPageCount + 1;
this.end = requestPage * this.currentPageCount;
}
public int getTotalPageCount() {
int totalRecord=getTotalRecordCount();
int count=getCurrentPageCount();
int total=totalRecord>count?(totalRecord/count)+1:1;
return total;
}
public int getCurrentPageCount() {
return currentPageCount;
}
public void setCurrentPageCount(int currentPageCount) {
this.currentPageCount = currentPageCount;
}
public int getRequestPage() {
return requestPage;
}
public void setRequestPage(int requestPage) {
this.requestPage = requestPage;
}
public int getBegin() {
return begin;
}
public void setBegin(int begin) {
this.begin = begin;
}
public int getEnd() {
return end;
}
public void setEnd(int end) {
this.end = end;
}
}