📄 pagedata.java
字号:
package com.singnet.data;
import java.util.List;
public class PageData
{
private int pageSize = 30; //per page size
private List items; //items
private int curPage = 0; //current page No.
private int prePage = 0; //previous page No.
private int nextPage = 0; //next page No.
private int totalCount = 0; //total items count
private int totalPages = 0; //total pages No.
private int[] pageIndex = new int[0]; //page indexs
private int startIndex = 0;
public PageData()
{
}
public PageData(List items, int totalCount)
{
setItems(items);
setTotalCount(totalCount);
setStartIndex(0);
}
public PageData(List items, int totalCount, int startIndex)
{
setItems(items);
setTotalCount(totalCount);
setStartIndex(startIndex);
}
public PageData(List items, int totalCount, int pageSize, int startIndex)
{
setPageSize(pageSize);
setItems(items);
setTotalCount(totalCount);
setStartIndex(startIndex);
}
public void setTotalCount(int totalCount)
{
if(totalCount <= 0) {
this.totalCount = 0;
}
else {
this.totalCount = totalCount;
int count = totalCount / pageSize;
if(totalCount % pageSize > 0) count ++;
this.totalPages = count;
int pageIndexNum = count > 10 ? 10 : count;
pageIndex = new int[pageIndexNum];
for(int i = 1; i <= pageIndexNum; i++) {
pageIndex[i - 1] = i;
}
}
}
public void setStartIndex(int startIndex)
{
if(totalCount <= 0) {
this.curPage = 0;
this.startIndex = 0;
}
else if(startIndex >= totalCount) {
this.curPage = totalPages;
this.startIndex = (totalPages - 1) * pageSize;
}
else if(startIndex < 0) {
this.curPage = 0;
this.startIndex = 0;
}
else {
this.curPage = startIndex / pageSize + 1;
this.startIndex += pageSize;
if(totalPages > 10 && curPage <= totalPages) {
if(curPage >= pageIndex[9]) {
int maxPageNum = curPage + 1 >= totalPages ? totalPages : curPage + 1;
for(int i = 9; i >= 0; i-- ) {
pageIndex[i] = maxPageNum;
maxPageNum--;
}
}
}
}
}
public int getCurPage()
{
return curPage;
}
public void setCurPage(int curPage)
{
this.curPage = curPage;
}
public List getItems()
{
return items;
}
public void setItems(List items)
{
this.items = items;
}
public int getNextPage()
{
return curPage + 1 > totalPages ? totalPages : curPage + 1;
}
public void setNextPage(int nextPage)
{
this.nextPage = nextPage;
}
public int[] getPageIndex()
{
return pageIndex;
}
public void setPageIndex(int[] pageIndex)
{
this.pageIndex = pageIndex;
}
public int getPageSize()
{
return pageSize;
}
public void setPageSize(int pageSize)
{
this.pageSize = pageSize;
}
public int getPrePage()
{
return curPage - 1 <= 1 ? 1 : curPage - 1;
}
public void setPrePage(int prePage)
{
this.prePage = prePage;
}
public int getStartIndex()
{
return startIndex;
}
public int getTotalCount()
{
return totalCount;
}
public int getTotalPages()
{
return totalPages;
}
public void setTotalPages(int totalPages)
{
this.totalPages = totalPages;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -