PageBean类:
public class PageBean {
private int pageSize = 10;
private int totalPage = 0;
private int totalRecord = 0;
private int currentPage = 1;
private boolean hasPreviousPage = false;
private boolean hasNextPage = false;
private int endPage = 0;
private int startPage = 0;
private boolean isPaging = true;
private List<?> data;
public PageBean() {
}
public PageBean(int pageSize) {
if (pageSize > 0) {
this.pageSize = pageSize;
}
}
public PageBean(int pageSize, int currentPage, boolean isPaging) {
if (pageSize > 0) {
this.pageSize = pageSize;
}
if (currentPage <= 0) {
currentPage = 1;
}
this.currentPage = currentPage;
this.isPaging = isPaging;
}
public void doPaging() {
if ((totalRecord % pageSize) == 0) {
totalPage = totalRecord / pageSize;
} else {
totalPage = totalRecord / pageSize + 1;
}
if (currentPage > 0) {
calculatePage();
}
}
private void calculatePage() {
if ((currentPage - 1) > 0) {
hasPreviousPage = true;
} else {
hasPreviousPage = false;
}
if (currentPage >= totalPage) {
hasNextPage = false;
} else {
hasNextPage = true;
}
if (currentPage * pageSize < totalRecord) {
endPage = currentPage * pageSize;
startPage = endPage - pageSize;
} else {
endPage = totalRecord;
startPage = pageSize * (totalPage - 1);
}
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}
public boolean isHasPreviousPage() {
return hasPreviousPage;
}
public void setHasPreviousPage(boolean hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}
public boolean isHasNextPage() {
return hasNextPage;
}
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}
public int getEndPage() {
return endPage;
}
public void setEndPage(int endPage) {
this.endPage = endPage;
}
public int getStartPage() {
return startPage;
}
public void setStartPage(int startPage) {
this.startPage = startPage;
}
public List<?> getData() {
return data;
}
public void setData(List<?> data) {
this.data = data;
}
public boolean isPaging() {
return isPaging;
}
public void setPaging(boolean isPaging) {
this.isPaging = isPaging;
}
}
使用:
@Override
public PageBean listActivationCodes(CouponModel form, UserVo currVisitor)
throws ServiceException {
List<CouponVo> coupons = listByCouponTemplateIdAndOrgId(form,
currVisitor);
PageBean page = new PageBean(form.getPageSize(),
form.getPureCurPageNum(), form.getIsPaging());
page.setData(coupons);
page.setTotalRecord(coupons.size());
return page;
}