カプセル化インタフェース戻りクラス
8422 ワード
カプセル化インタフェースの結果
1、基本返却類ResultSupport.java
2.非ページングはresultクラスBaseResultを返す.java
3.ページングはクラスBasePageResultに戻る.java
1、基本返却類ResultSupport.java
public class ResultSupport implements Serializable {
private static final long serialVersionUID = -2235152751651905167L;
private boolean success = true;
private String resultMsg;
private int errorCode;
public ResultSupport() {
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getResultMsg() {
return resultMsg;
}
public void setResultMsg(String resultMsg) {
this.resultMsg = resultMsg;
}
public void setErrorCode(ErpgwReturnCode errorCode) {
this.resultMsg = errorCode.getDesc();
this.success = false;
this.errorCode = errorCode.getCode();
}
public int getErrorCode() {
return errorCode;
}
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
}
2.非ページングはresultクラスBaseResultを返す.java
public class BaseResult<T> extends ResultSupport {
private static final long serialVersionUID = 4999091548448313101L;
protected T value;
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public static <U> BaseResult<U> buildFailResult(int errorCode, String errorMsg, U value) {
BaseResult<U> baseResult = new BaseResult<U>();
baseResult.setSuccess(false);
baseResult.setErrorCode(errorCode);
baseResult.setValue(value);
baseResult.setResultMsg(errorMsg);
return baseResult;
}
public static <U> BaseResult<U> buildSuccessResult(U value) {
BaseResult<U> baseResult = new BaseResult<U>();
baseResult.setSuccess(true);
baseResult.setValue(value);
return baseResult;
}
}
3.ページングはクラスBasePageResultに戻る.java
public class BasePageResult<T> extends ResultSupport {
private static final long serialVersionUID = 7378807577314788084L;
protected int pageNo = 1;
protected int pageSize;
protected int totalCount;
protected boolean hasNext;
protected List<T> list;
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
if (pageNo <= 0) {
pageNo = 1;
}
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
if (pageSize < 0) {
pageSize = 0;
}
this.pageSize = pageSize;
}
public int getStartRow() {
return (pageNo - 1) * pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public boolean isHasNext() {
return hasNext;
}
public void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
}
}