java的Result类

 
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Result <T> extends BaseDomain implements Serializable {
private String code;
private String msg;
private T data;

private Result) {
this.code = UnifyStrErrorCode.SUCCESS.getCode);
this.msg = UnifyStrErrorCode.SUCCESS.getMsg);
}

private ResultT data) {
this.code = UnifyStrErrorCode.SUCCESS.getCode);
this.msg = UnifyStrErrorCode.SUCCESS.getMsg);
this.setDatadata);
}

private ResultString code, String msg) {
this.code = UnifyStrErrorCode.SUCCESS.getCode);
this.msg = UnifyStrErrorCode.SUCCESS.getMsg);
this.setCodecode);
this.setMsgmsg);
}

private ResultString code, String msg, T data) {
this.code = UnifyStrErrorCode.SUCCESS.getCode);
this.msg = UnifyStrErrorCode.SUCCESS.getMsg);
this.setCodecode);
this.setMsgmsg);
this.setDatadata);
}

public Result<T> setErrorString code, String msg) {
this.setCodecode);
this.setMsgmsg);
return this;
}

public Result<T> setErrorUnifyStrErrorCode errorCode) {
this.setCodeerrorCode.getCode));
this.setMsgerrorCode.getMsg));
return this;
}

public boolean isSuccess) {
return StringUtils.equalsthis.getCode), UnifyStrErrorCode.SUCCESS.getCode));
}

public static Result instance) {
return new Result);
}

public static <T> Result instanceT data) {
return new Resultdata);
}

public static <T> Result instanceString code, String msg) {
return new Resultcode, msg);
}

public static <T> Result instanceString code, String msg, T data) {
return new Resultcode, msg, data);
}

public String getCode) {
return this.code;
}

public void setCodeString code) {
this.code = code;
}

public String getMsg) {
return this.msg;
}

public void setMsgString msg) {
this.msg = msg;
}

public T getData) {
return this.data;
}

public void setDataT data) {
this.data = data;
}

public Map<String,Object> toJsonMap){
Map<String,Object> map = new HashMap<>);
map.put"data",this.data);
map.put"msg",this.msg);
map.put"code",this.code);
return map;
}

}

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、


 
import org.apache.commons.lang.builder.ToStringBuilder;

import java.io.Serializable;


public class BaseDomain implements Serializable {
public BaseDomain) {
}

public String toString) {
return ToStringBuilder.reflectionToStringthis);
}
}



Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注