com.luues.util.datawrap.PageDataWrap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-util Show documentation
Show all versions of commons-util Show documentation
A Simple Tool Operations Class
package com.luues.util.datawrap;
import java.io.Serializable;
import java.lang.reflect.Field;
public class PageDataWrap extends DataWrap implements Serializable {
private int currPage;
private int pageSize;
private int total;
private int pageCount;
public PageDataWrap() {
super();
}
public PageDataWrap(int resultCode) {
this.resultCode = resultCode;
resh();
}
public PageDataWrap(int resultCode, String resultMsg) {
this.resultCode = resultCode;
this.resultMsg = resultMsg;
resh();
}
public void setPage(Page page) {
this.put("rows", page.getData());
this.pageCount = page.getPageCount();
this.pageSize = page.getPageSize();
this.currPage = page.getCurrPage();
this.total = (int) page.getTotal();
resh();
}
public int getResultCode() {
return this.resultCode;
}
public void setResultCode(int resultCode) {
this.resultCode = resultCode;
}
public String getResultMsg() {
return this.resultMsg;
}
public void setResultMsg(String resultMsg) {
this.resultMsg = resultMsg;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
//this.currPage = ResultCode.getCurrPage();
//this.pageSize = ResultCode.getPageSize();
this.total = total;
//this.pageCount = this.total == 0 ? 1 : this.total % ResultCode.getPageSize() == 0 ? this.total / ResultCode.getPageSize() : this.total / ResultCode.getPageSize() + 1;
resh();
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public Object getData() {
return this.get("rows");
}
public void putData(Object value) {
this.put("rows", value);
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
private void resh() {
Field[] fields = this.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
this.put(fields[i].getName(), getFieldValueByName(fields[i].getName(), this));
}
fields = this.getClass().getSuperclass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
this.put(fields[i].getName(), getFieldValueByName(fields[i].getName(), this));
}
}
}