📄 pagemanage.java
字号:
package com.util;
import java.util.*;
public class PageManage {
//分页显示数据
private int currentpage = 1; //当前页
private int i_page_count = 10; //每页显示数据
private int totalPagenum = 0; //总页数
private int totalObjectnum = 0; //总数据条目数
private List objectList; //需要分页的数据
private List currentList; //当前页取出的数据;
public PageManage() {}
public PageManage(List objectList) {
this.setObjectList(objectList);
this.totalObjectnum = this.getTotalObjectnum();
}
public int getI_page_count() {
return i_page_count;
}
public List getObjectList() {
return objectList;
}
//计算总页数
public int getTotalPagenum() {
if (totalObjectnum % i_page_count == 0) {
totalPagenum = totalObjectnum / i_page_count;
}
else {
totalPagenum = totalObjectnum / i_page_count + 1;
}
return totalPagenum;
}
public int getTotalObjectnum() {
return this.getObjectList().size();
}
public int getCurrentpage() {
return currentpage;
}
//获得当前页的list数据
public List getCurrentList() {
this.currentList = null;
this.currentList = new ArrayList();
int begin_num = currentpage * i_page_count - i_page_count + 1; //开始取的数据位置
//System.out.println("开始数据 = "+begin_num);
int isbegin = 1;
int isend = 0;
for (int index = 0; index < this.getTotalObjectnum(); index++) {
if (isbegin < begin_num) {
isbegin = isbegin + 1;
continue; //如果小于要开始取的数据位置,则继续循环;
}
else if (isend < i_page_count) { //如果已经取了每页需要显示的数据条数,则跳出循环不再取数据
this.currentList.add(this.objectList.get(index));
isend = isend + 1;
}
else {
break;
}
}
return this.currentList;
}
public void setI_page_count(int i_page_count) {
this.i_page_count = i_page_count;
}
public void setObjectList(List objectList) {
this.objectList = objectList;
}
public void setTotalPagenum(int totalPagenum) {
this.totalPagenum = totalPagenum;
}
public void setTotalObjectnum(int totalObjectnum) {
this.totalObjectnum = this.getObjectList().size();
}
public void setCurrentpage(int currentpage) {
if (currentpage < 1) {
currentpage = 1;
}
if (currentpage > this.totalPagenum) {
currentpage = this.totalPagenum;
}
this.currentpage = currentpage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -