public interface Paginable {
public int getTotalCount();
public int getPageCount();
public int getPageSize();
public int getCurrentPage();
public int getStartIndex();
public boolean isFirstPage();
public boolean isLastPage();
public int getNextPage();
public int getPrePage();
}
Java代码
publicclass SimplePage implements Paginable {
publicfinalstaticint PAGESIZE = 4;
// Total count of records
protectedint totalCount;
// The size of records per page
protectedint pageSize = PAGESIZE;
// Current page
protectedint currentPage;
// The count of pages
privateint pageCount;
public SimplePage() {
}
public SimplePage(int totalCount) {
setPageSize(PAGESIZE);
setTotalCount(totalCount);
setCurrentPage(1);
}
public SimplePage(int currentPage, int totalCount) {
setPageSize(PAGESIZE);
setTotalCount(totalCount);
setCurrentPage(currentPage);
}
public SimplePage(int currentPage, int pageSize, int totalCount) {
setPageSize(pageSize);
setTotalCount(totalCount);
setCurrentPage(currentPage);
}
publicboolean isFirstPage() {
return currentPage <= 1;
}
publicboolean isLastPage() {
return currentPage >= pageCount;
}
publicint getNextPage() {
if (isLastPage()) {
return currentPage;
} else {
return currentPage + 1;
}
}
publicint getPrePage() {
if (isFirstPage()) {
return currentPage;
} else {
return currentPage - 1;
}
}
publicint getCurrentPage() {
return currentPage;
}
publicint getStartIndex() {
return (currentPage - 1) * pageSize;
}
publicvoid setCurrentPage(int currentPage) {
if (totalCount <= 0)
this.currentPage = 0;
elseif (currentPage >= pageCount)
this.currentPage = pageCount;
elseif (currentPage <= 1)
this.currentPage = 1;
else {
this.currentPage = currentPage;
}
}
publicint getPageSize() {
return pageSize;
}
publicvoid setPageSize(int pageSize) {
this.pageSize = pageSize;
}
publicint getTotalCount() {
return totalCount;
}
publicvoid setTotalCount(int totalCount) {
if (totalCount > 0) {
this.totalCount = totalCount;
pageCount = totalCount / pageSize;
if (totalCount % pageSize > 0)
pageCount++;
} else {
this.totalCount = 0;
}
}
publicint getPageCount() {
return pageCount;
}
publicvoid setPageCount(int pageCount) {
this.pageCount = pageCount;
}
}
public class SimplePage implements Paginable {
public final static int PAGESIZE = 4;
// Total count of records
protected int totalCount;
// The size of records per page
protected int pageSize = PAGESIZE;
// Current page
protected int currentPage;
// The count of pages
private int pageCount;
public SimplePage() {
}
public SimplePage(int totalCount) {
setPageSize(PAGESIZE);
setTotalCount(totalCount);
setCurrentPage(1);
}
public SimplePage(int currentPage, int totalCount) {
setPageSize(PAGESIZE);
setTotalCount(totalCount);
setCurrentPage(currentPage);
}
public SimplePage(int currentPage, int pageSize, int totalCount) {
setPageSize(pageSize);
setTotalCount(totalCount);
setCurrentPage(currentPage);
}
public boolean isFirstPage() {
return currentPage <= 1;
}
public boolean isLastPage() {
return currentPage >= pageCount;
}
public int getNextPage() {
if (isLastPage()) {
return currentPage;
} else {
return currentPage + 1;
}
}
public int getPrePage() {
if (isFirstPage()) {
return currentPage;
} else {
return currentPage - 1;
}
}
public int getCurrentPage() {
return currentPage;
}
public int getStartIndex() {
return (currentPage - 1) * pageSize;
}
public void setCurrentPage(int currentPage) {
if (totalCount <= 0)
this.currentPage = 0;
else if (currentPage >= pageCount)
this.currentPage = pageCount;
else if (currentPage <= 1)
this.currentPage = 1;
else {
this.currentPage = currentPage;
}
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
if (totalCount > 0) {
this.totalCount = totalCount;
pageCount = totalCount / pageSize;
if (totalCount % pageSize > 0)
pageCount++;
} else {
this.totalCount = 0;
}
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
}