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