package com.walker.common;
|
|
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlTransient;
|
import java.io.Serializable;
|
import java.util.List;
|
|
|
/**
|
* 分页对象
|
*
|
* @author 时克英
|
*/
|
@Deprecated
|
@XmlRootElement(name = "SplitPageInfo")
|
public abstract class SplitPageInfo implements Serializable {
|
private static final long serialVersionUID = -1610997402731940907L;
|
/**
|
* 数据行数
|
*/
|
private int totalRowsAmount;
|
private boolean rowsAmountSet;
|
private int pageSize;
|
private int currentPage;
|
private int nextPage;
|
private int previousPage;
|
private int totalPages;
|
private int pageRowBegin;
|
private int pageRowEnd;
|
private boolean hasToFirstPage;
|
private boolean hasNext;
|
private boolean hasPrevious;
|
private boolean hasLastPage;
|
private boolean listIsEmpty;
|
private boolean isDefaultShow;
|
private int sizeNum;
|
private List<?> result;
|
/**
|
* 形如[1],[2],[3],[4],[5]分页得开始
|
*/
|
private int startPage;
|
/**
|
* 形如[1],[2],[3],[4],[5]分页的结束
|
*/
|
private int endPage;
|
|
public SplitPageInfo() {
|
this.pageSize = 10;
|
this.sizeNum = 2;
|
this.currentPage = 1;
|
this.listIsEmpty = true;
|
this.isDefaultShow=true;
|
}
|
|
/**
|
* 获取数据条数
|
*
|
* @return 数据条数
|
*/
|
@XmlElement(name = "rowsNumber")
|
public int getTotalRowsAmount() {
|
return this.totalRowsAmount;
|
}
|
|
/**
|
* 设置数据条数
|
*
|
* @param totalRowsAmount 数据条数
|
*/
|
public void setTotalRowsAmount(int totalRowsAmount) {
|
this.totalRowsAmount = totalRowsAmount;
|
this.rowsAmountSet = true;
|
if (totalRowsAmount > 0) {
|
this.listIsEmpty = false;
|
}
|
if (this.totalRowsAmount % this.pageSize == 0) {
|
this.totalPages = (this.totalRowsAmount / this.pageSize);
|
} else {
|
this.totalPages = (this.totalRowsAmount / this.pageSize + 1);
|
}
|
if (this.currentPage <= 0) {
|
this.currentPage = 1;
|
}
|
if (this.currentPage > this.totalPages) {
|
this.currentPage = this.totalPages;
|
}
|
this.hasToFirstPage = this.currentPage > 1;
|
if (this.currentPage < this.totalPages) {
|
this.nextPage = (this.currentPage + 1);
|
this.hasNext = true;
|
} else {
|
this.nextPage = this.currentPage;
|
this.hasNext = false;
|
}
|
if (this.currentPage > 1) {
|
this.previousPage = (this.currentPage - 1);
|
this.hasPrevious = true;
|
} else {
|
this.previousPage = this.currentPage;
|
this.hasPrevious = false;
|
}
|
if (this.currentPage > 0) {
|
this.pageRowBegin = ((this.currentPage - 1) * this.pageSize + 1);
|
} else {
|
this.pageRowBegin = 0;
|
}
|
if (this.currentPage < this.totalPages) {
|
this.pageRowEnd = (this.pageRowBegin + this.pageSize - 1);
|
} else {
|
this.pageRowEnd = (this.pageRowBegin + (this.totalRowsAmount - 1) % this.pageSize);
|
if (this.pageRowEnd < 0) {
|
this.pageRowEnd = 0;
|
}
|
}
|
this.hasLastPage = this.currentPage != this.totalPages;
|
|
calcPage(currentPage, totalPages, sizeNum);
|
}
|
|
|
/**
|
* 获取是否设置了数据条数
|
*
|
* @return 数据条数
|
*/
|
@XmlTransient
|
public boolean getRowsAmountSet() {
|
return this.rowsAmountSet;
|
}
|
|
|
/**
|
* 设置否设置了数据条数
|
*
|
* @param rowsAmountSet 是否数据条数设置
|
*/
|
@XmlTransient
|
public void setRowsAmountSet(boolean rowsAmountSet) {
|
this.rowsAmountSet = rowsAmountSet;
|
}
|
|
|
/**
|
* 获取每页数据条数
|
*
|
* @return 每页数据条数
|
*/
|
@XmlElement(name = "pageSize")
|
public int getPageSize() {
|
return this.pageSize;
|
}
|
|
|
/**
|
* 设置每页数据条数
|
*
|
* @param pageSize 每页数据条数
|
*/
|
public void setPageSize(int pageSize) {
|
this.pageSize = pageSize;
|
}
|
|
|
/**
|
* 获取当前页码
|
*
|
* @return 当前页码
|
*/
|
@XmlElement(name = "currentPage")
|
public int getCurrentPage() {
|
return this.currentPage;
|
}
|
|
|
/**
|
* 设置当前页码
|
*
|
* @param currentPage 当前页码
|
*/
|
public void setCurrentPage(int currentPage) {
|
this.currentPage = currentPage;
|
}
|
|
|
/**
|
* 获取下一页页码
|
*
|
* @return 下一页页码
|
*/
|
@XmlTransient
|
public int getNextPage() {
|
return this.nextPage;
|
}
|
|
|
/**
|
* 设置下一页页码
|
*
|
* @param nextPage 下一页页码
|
*/
|
public void setNextPage(int nextPage) {
|
this.nextPage = nextPage;
|
}
|
|
|
/**
|
* 获取前一页页码
|
*
|
* @return 前一页页码
|
*/
|
@XmlTransient
|
public int getPreviousPage() {
|
return this.previousPage;
|
}
|
|
|
/**
|
* 设置前一页页码
|
*
|
* @param previousPage 前一页页码
|
*/
|
public void setPreviousPage(int previousPage) {
|
this.previousPage = previousPage;
|
}
|
|
|
/**
|
* 获取总页数
|
*
|
* @return 总页数
|
*/
|
@XmlTransient
|
public int getTotalPages() {
|
return this.totalPages;
|
}
|
|
/**
|
* 设置总页数
|
*
|
* @param totalPages 总页数
|
*/
|
public void setTotalPages(int totalPages) {
|
this.totalPages = totalPages;
|
}
|
|
|
/**
|
* 获取当前页起始行号
|
*
|
* @return 当前页起始行号
|
*/
|
@XmlTransient
|
public int getPageRowBegin() {
|
return this.pageRowBegin;
|
}
|
|
/**
|
* 设置当前页起始行号
|
*
|
* @param pageRowBegin 当前页起始行号
|
*/
|
public void setPageRowBegin(int pageRowBegin) {
|
this.pageRowBegin = pageRowBegin;
|
}
|
|
|
/**
|
* 获取当前页结束行号
|
*
|
* @return 前页结束行号
|
*/
|
@XmlTransient
|
public int getPageRowEnd() {
|
return this.pageRowEnd;
|
}
|
|
|
/**
|
* 设置当前页结束行号
|
*
|
* @param pageRowEnd 前页结束行号
|
*/
|
public void setPageRowEnd(int pageRowEnd) {
|
this.pageRowEnd = pageRowEnd;
|
}
|
|
|
/**
|
* 获取是否有下一页
|
*
|
* @return 是否有下一页
|
*/
|
@XmlTransient
|
public boolean getHasNext() {
|
return this.hasNext;
|
}
|
|
|
/**
|
* 设置是否有下一页
|
*
|
* @param hasNext 是否有下一页
|
*/
|
public void setHasNext(boolean hasNext) {
|
this.hasNext = hasNext;
|
}
|
|
/**
|
* 获取是否有前一页
|
*
|
* @return 是否有前一页
|
*/
|
@XmlTransient
|
public boolean getHasPrevious() {
|
return this.hasPrevious;
|
}
|
|
|
/**
|
* 设置是否有前一页
|
*
|
* @param hasPrevious 是否有前一页
|
*/
|
public void setHasPrevious(boolean hasPrevious) {
|
this.hasPrevious = hasPrevious;
|
}
|
|
|
/**
|
* 获取是否有最后一页
|
*
|
* @return 是否有最后一页
|
*/
|
@XmlTransient
|
public boolean getHasLastPage() {
|
return this.hasLastPage;
|
}
|
|
/**
|
* 设置是否有最后一页
|
*
|
* @param hasLastPage 是否有最后一页
|
*/
|
public void setHasLastPage(boolean hasLastPage) {
|
this.hasLastPage = hasLastPage;
|
}
|
|
|
/**
|
* 获取返回数据是否为空
|
*
|
* @return 返回数据是否为空
|
*/
|
@XmlTransient
|
public boolean getListIsEmpty() {
|
return this.listIsEmpty;
|
}
|
|
|
/**
|
* 设置返回结果列表是否为空
|
*
|
* @param listIsEmpty 返回结果列表是否为空
|
*/
|
public void setListIsEmpty(boolean listIsEmpty) {
|
this.listIsEmpty = listIsEmpty;
|
}
|
|
/**
|
* 获取是否有第一页
|
*
|
* @return 是否有第一页
|
*/
|
@XmlTransient
|
public boolean getHasToFirstPage() {
|
return this.hasToFirstPage;
|
}
|
|
|
/**
|
* 设置是否有第一页
|
*
|
* @param hasToFirstPage 是否有第一页
|
*/
|
public void setHasToFirstPage(boolean hasToFirstPage) {
|
this.hasToFirstPage = hasToFirstPage;
|
}
|
|
|
/**
|
* 返回结果列表
|
*
|
* @return 结果列表
|
*/
|
public List<?> getResult() {
|
return result;
|
}
|
|
|
/**
|
* 设置结果列表
|
*
|
* @param result 结果列表
|
*/
|
public void setResult(List<?> result) {
|
this.result = result;
|
}
|
|
/**
|
* 获取起始页
|
*
|
* @return 起始页
|
*/
|
public int getStartPage() {
|
return startPage;
|
}
|
|
/**
|
* 设置起始页
|
*
|
* @param startPage 起始页
|
*/
|
public void setStartPage(int startPage) {
|
this.startPage = startPage;
|
}
|
|
/**
|
* 获取结束页
|
*
|
* @return 结束页
|
*/
|
public int getEndPage() {
|
return endPage;
|
}
|
|
/**
|
* 设置结束页
|
*
|
* @param endPage 结束页
|
*/
|
public void setEndPage(int endPage) {
|
this.endPage = endPage;
|
}
|
|
@Override
|
public String toString() {
|
return new StringBuilder()
|
.append("pageSize=").append(this.pageSize)
|
.append("currentPage=").append(this.currentPage)
|
.append("totalRowsAmount=").append(this.totalRowsAmount)
|
.append("pageRowBegin=").append(this.pageRowBegin)
|
.append("pageRowEnd=").append(this.pageRowEnd)
|
.toString();
|
}
|
|
|
/**
|
* 计算显示当前分页的起始页
|
*
|
* @param pageNum 当前页码
|
* @param pageCount 总页数
|
* @param sideNum 分页系数 分页条中显示几个数字页码。 显示数字页码个数 = 2 * sideNum + 1
|
*/
|
public void calcPage(int pageNum, int pageCount, int sideNum) {
|
|
if (pageCount <= sideNum) {
|
endPage = pageCount;
|
} else {
|
if ((sideNum + pageNum) >= pageCount) {
|
endPage = pageCount;
|
} else {
|
endPage = sideNum + pageNum;
|
if ((sideNum + pageNum) <= (2 * sideNum + 1)) {
|
if ((2 * sideNum + 1) >= pageCount) {
|
endPage = pageCount;
|
} else {
|
endPage = 2 * sideNum + 1;
|
}
|
} else {
|
endPage = sideNum + pageNum;
|
}
|
}
|
}
|
|
if (pageNum <= sideNum) {
|
startPage = 1;
|
} else {
|
if ((pageNum + sideNum) >= pageCount) {
|
if ((2 * sideNum + 1) >= pageCount) {
|
if ((pageCount - 2 * sideNum) >= 1) {
|
startPage = pageCount - 2 * sideNum;
|
} else {
|
startPage = 1;
|
}
|
} else {
|
startPage = pageCount - 2 * sideNum;
|
}
|
} else {
|
if ((pageNum - sideNum) >= 1) {
|
startPage = pageNum - sideNum;
|
} else {
|
startPage = 1;
|
}
|
}
|
}
|
}
|
|
/**
|
* 生成分页展现html代码
|
*
|
* @return 分页展现html代码
|
*/
|
public abstract String getPaginateHtml();
|
|
public int getSizeNum() {
|
return sizeNum;
|
}
|
|
public void setSizeNum(int sizeNum) {
|
this.sizeNum = sizeNum;
|
}
|
|
public boolean isDefaultShow() {
|
return isDefaultShow;
|
}
|
|
public void setDefaultShow(boolean defaultShow) {
|
isDefaultShow = defaultShow;
|
}
|
}
|