📄 pageinfo.java
字号:
package com.xfaccp.base;
public class PageInfo {
private int totalRows = 0; // 记录总数
private int pageSize = 3; // 每页显示数据条数,默认为3条记录
private int totalPages = 0; // 总页数
private int currentPage = 1; // 当前页数(初始显示为第一页)
private boolean hasPrevious = false; // 是否有上一页
private boolean hasNext = false; // 是否有下一页
public PageInfo() {
}
// 自定义方法用于刷新当前页面信息
public void refresh() {
//只有一页信息case
if (totalPages <1) {
hasPrevious = false;
hasNext = false;
}
//不止一页但当前为第一页的case
else if (currentPage == 1) {
hasPrevious = false;
hasNext = true;
}
//不止一页而且当前页为最后一页
else if (currentPage == totalPages) {
hasPrevious = true;
hasNext = false;
}
//不止一页当前页为中间页
else {
hasPrevious = true;
hasNext = true;
}
}
public void init(int totalRows, int pageSize) {
this.totalRows = totalRows;
this.pageSize = pageSize;
totalPages = ((totalRows + pageSize) - 1) / pageSize;
//刷新当前页面信息
refresh();
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
refresh();
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
refresh();
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
refresh();
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
refresh();
}
// 跳到第一页
public void first() {
currentPage = 1;
this.setHasPrevious(false);
refresh();
}
// 取得上一页(重新设定当前页面即可)
public void previous() {
if(currentPage>0)
{
currentPage--;
}
refresh();
}
// 取得下一页
public void next() {
System.out.println("next: totalPages: " + totalPages +" currentPage : " + currentPage);
if (currentPage < totalPages) {
currentPage++;
}
refresh();
}
// 跳到最后一页
public void last() {
currentPage = totalPages;
this.setHasNext(false);
refresh();
}
public boolean isHasNext() {
return hasNext;
}
public void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
}
public boolean isHasPrevious() {
return hasPrevious;
}
public void setHasPrevious(boolean hasPrevious) {
this.hasPrevious = hasPrevious;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -