📄 pageagent.java
字号:
package com.pegasus.framework.component.taglib.html.pager;
import java.io.Serializable;
public class PageAgent implements Serializable {
private static final long serialVersionUID = 1L;
private static final int DEFAULT_FETCH_SIZE = 10;
private static final int DEFAULT_PAGENO = 1;
private int fetchSize;
private int pageNo;
private int totalPageCount;
private int totalObjectCount;
public PageAgent() {
this(1, 10);
}
public PageAgent(int pageNo) {
this(pageNo, 10);
}
public PageAgent(int pageNo, int fetchSize) {
totalObjectCount = 10;
setFetchSize(fetchSize);
setPageNo(pageNo);
}
public int getFetchSize() {
return fetchSize;
}
public void setFetchSize(int fetchSize) {
this.fetchSize = fetchSize >= 1 ? fetchSize : 1;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo >= 1 ? pageNo : 1;
}
public int getTotalObjectCount() {
return totalObjectCount;
}
public void setTotalObjectCount(int totalObjectCount) {
this.totalObjectCount = totalObjectCount;
}
public int getTotalPageCount() {
calculatePage();
return totalPageCount;
}
public boolean isFirstPage() {
return pageNo == 1;
}
public boolean getIsFirstPage() {
return isFirstPage();
}
public PageAgent moveToFirstPage() {
return jumpToPage(1);
}
public boolean isLastPage() {
return pageNo == getTotalPageCount();
}
public boolean getIsLastPage() {
return isLastPage();
}
public PageAgent moveToLastPage() {
return jumpToPage(getTotalPageCount());
}
public boolean hasNextPage() {
return pageNo < getTotalPageCount();
}
public boolean getHasNextPage() {
return hasNextPage();
}
public PageAgent moveToNextPage() {
int nextPageNo = pageNo + 1;
return jumpToPage(nextPageNo);
}
public boolean hasPrecedingPage() {
return pageNo > 1;
}
public boolean getHasPrecedingPage() {
return hasPrecedingPage();
}
public PageAgent moveToPrecedingPage() {
int nextPageNo = pageNo - 1;
return jumpToPage(nextPageNo);
}
public int getFirstObjectIndexOfResult() {
return (pageNo - 1) * fetchSize;
}
private void calculatePage() {
if (totalObjectCount == 0) {
totalPageCount = 0;
} else {
totalPageCount = totalObjectCount / fetchSize;
int d = totalObjectCount % fetchSize;
if (d > 0)
totalPageCount++;
}
}
public PageAgent jumpToPage(int destPageNo) {
PageAgent pageAgent = new PageAgent(destPageNo, fetchSize);
pageAgent.setTotalObjectCount(totalObjectCount);
return pageAgent;
}
public int hashCode() {
return 23;
}
public String toString() {
return "fetchSize=" + String.valueOf(fetchSize) + ";pageNo=" + String.valueOf(pageNo);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -