|
|
|
@ -10,26 +10,26 @@ public class Paginator implements Serializable {
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
|
|
private final int limit;
|
|
|
|
|
private int page = 1;
|
|
|
|
|
private int pageNum = 1;
|
|
|
|
|
private final int totalCount;
|
|
|
|
|
|
|
|
|
|
public Paginator(int page, int limit, int totalCount) {
|
|
|
|
|
public Paginator(int pageNum, int limit, int totalCount) {
|
|
|
|
|
super();
|
|
|
|
|
this.limit = limit;
|
|
|
|
|
this.totalCount = totalCount;
|
|
|
|
|
this.page = computePageNo(page);
|
|
|
|
|
this.pageNum = computePageNo(pageNum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSessionPagination(Paginator paginator){
|
|
|
|
|
RequestContextHolder.currentRequestAttributes().setAttribute(PagingConstants.Session.PAGE_INFO.getCode(), paginator, RequestAttributes.SCOPE_REQUEST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPage() {
|
|
|
|
|
return page;
|
|
|
|
|
public int getPageNum() {
|
|
|
|
|
return pageNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPage(int page) {
|
|
|
|
|
this.page = page;
|
|
|
|
|
public void setPage(int pageNum) {
|
|
|
|
|
this.pageNum = pageNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getLimit() {
|
|
|
|
@ -41,53 +41,53 @@ public class Paginator implements Serializable {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isFirstPage() {
|
|
|
|
|
return page <= 1;
|
|
|
|
|
return pageNum <= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isLastPage() {
|
|
|
|
|
return page >= getTotalPages();
|
|
|
|
|
return pageNum >= getTotalPages();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPrePage() {
|
|
|
|
|
if (isHasPrePage()) {
|
|
|
|
|
return page - 1;
|
|
|
|
|
return pageNum - 1;
|
|
|
|
|
} else {
|
|
|
|
|
return page;
|
|
|
|
|
return pageNum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNextPage() {
|
|
|
|
|
if (isHasNextPage()) {
|
|
|
|
|
return page + 1;
|
|
|
|
|
return pageNum + 1;
|
|
|
|
|
} else {
|
|
|
|
|
return page;
|
|
|
|
|
return pageNum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isDisabledPage(int page) {
|
|
|
|
|
return ((page < 1) || (page > getTotalPages()) || (page == this.page));
|
|
|
|
|
return ((page < 1) || (page > getTotalPages()) || (page == this.pageNum));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isHasPrePage() {
|
|
|
|
|
return (page - 1 >= 1);
|
|
|
|
|
return (pageNum - 1 >= 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isHasNextPage() {
|
|
|
|
|
return (page + 1 <= getTotalPages());
|
|
|
|
|
return (pageNum + 1 <= getTotalPages());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getStartRow() {
|
|
|
|
|
if (getLimit() <= 0 || totalCount <= 0)
|
|
|
|
|
return 0;
|
|
|
|
|
return page > 0 ? (page - 1) * getLimit() + 1 : 0;
|
|
|
|
|
return pageNum > 0 ? (pageNum - 1) * getLimit() + 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getEndRow() {
|
|
|
|
|
return page > 0 ? Math.min(limit * page, getTotalCount()) : 0;
|
|
|
|
|
return pageNum > 0 ? Math.min(limit * pageNum, getTotalCount()) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getOffset() {
|
|
|
|
|
return page > 0 ? (page - 1) * getLimit() : 0;
|
|
|
|
|
return pageNum > 0 ? (pageNum - 1) * getLimit() : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getTotalPages() {
|
|
|
|
@ -105,8 +105,8 @@ public class Paginator implements Serializable {
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected int computePageNo(int page) {
|
|
|
|
|
return computePageNumber(page, limit, totalCount);
|
|
|
|
|
protected int computePageNo(int pageNum) {
|
|
|
|
|
return computePageNumber(pageNum, limit, totalCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int computeLastPageNumber(int totalItems, int pageSize) {
|
|
|
|
@ -119,23 +119,23 @@ public class Paginator implements Serializable {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int computePageNumber(int page, int pageSize, int totalItems) {
|
|
|
|
|
if (page <= 1) {
|
|
|
|
|
private static int computePageNumber(int pageNum, int pageSize, int totalItems) {
|
|
|
|
|
if (pageNum <= 1) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (Integer.MAX_VALUE == page
|
|
|
|
|
|| page > computeLastPageNumber(totalItems, pageSize)) { // last
|
|
|
|
|
if (Integer.MAX_VALUE == pageNum
|
|
|
|
|
|| pageNum > computeLastPageNumber(totalItems, pageSize)) { // last
|
|
|
|
|
// page
|
|
|
|
|
return computeLastPageNumber(totalItems, pageSize);
|
|
|
|
|
}
|
|
|
|
|
return page;
|
|
|
|
|
return pageNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
final StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.append("Paginator");
|
|
|
|
|
sb.append("{page=").append(page);
|
|
|
|
|
sb.append("{pageNum=").append(pageNum);
|
|
|
|
|
sb.append(", limit=").append(limit);
|
|
|
|
|
sb.append(", totalCount=").append(totalCount);
|
|
|
|
|
sb.append('}');
|
|
|
|
|