| ÎļþÃû´Ó src/main/java/com/chinaztt/mes/docx/util/R.java ÐÞ¸Ä |
| | |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | public class R<T> implements Serializable { |
| | | /** |
| | | * éç¨è¿å对象 |
| | | * @param <T> |
| | | */ |
| | | public class Result<T> implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | // "è¿åæ è®°ï¼æåæ è®°=0ï¼å¤±è´¥æ è®°=1" |
| | | private int code; |
| | |
| | | // "æ°æ®" |
| | | private T data; |
| | | |
| | | public static <T> R<T> ok() { |
| | | public static <T> Result<T> ok() { |
| | | return restResult(null, CommonConstants.SUCCESS, (String) null); |
| | | } |
| | | |
| | | public static <T> R<T> ok(T data) { |
| | | public static <T> Result<T> ok(T data) { |
| | | return restResult(data, CommonConstants.SUCCESS, (String) null); |
| | | } |
| | | |
| | | public static <T> R<T> ok(T data, String msg) { |
| | | public static <T> Result<T> ok(T data, String msg) { |
| | | return restResult(data, CommonConstants.SUCCESS, msg); |
| | | } |
| | | |
| | | public static <T> R<T> failed() { |
| | | public static <T> Result<T> failed() { |
| | | return restResult(null, CommonConstants.FAIL, (String) null); |
| | | } |
| | | |
| | | public static <T> R<T> failed(String msg) { |
| | | public static <T> Result<T> failed(String msg) { |
| | | return restResult(null, CommonConstants.FAIL, msg); |
| | | } |
| | | |
| | | public static <T> R<T> failed(T data) { |
| | | public static <T> Result<T> failed(T data) { |
| | | return restResult(data, CommonConstants.FAIL, (String) null); |
| | | } |
| | | |
| | | public static <T> R<T> failed(T data, String msg) { |
| | | public static <T> Result<T> failed(T data, String msg) { |
| | | return restResult(data, CommonConstants.FAIL, msg); |
| | | } |
| | | |
| | | private static <T> R<T> restResult(T data, int code, String msg) { |
| | | R<T> apiResult = new R(); |
| | | private static <T> Result<T> restResult(T data, int code, String msg) { |
| | | Result<T> apiResult = new Result(); |
| | | apiResult.setCode(code); |
| | | apiResult.setData(data); |
| | | apiResult.setMsg(msg); |
| | |
| | | return "R(code=" + this.getCode() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")"; |
| | | } |
| | | |
| | | public R() { |
| | | public Result() { |
| | | } |
| | | |
| | | public R(int code, String msg, T data) { |
| | | public Result(int code, String msg, T data) { |
| | | this.code = code; |
| | | this.msg = msg; |
| | | this.data = data; |
| | |
| | | return this.code; |
| | | } |
| | | |
| | | public R<T> setCode(int code) { |
| | | public Result<T> setCode(int code) { |
| | | this.code = code; |
| | | return this; |
| | | } |
| | |
| | | return this.msg; |
| | | } |
| | | |
| | | public R<T> setMsg(String msg) { |
| | | public Result<T> setMsg(String msg) { |
| | | this.msg = msg; |
| | | return this; |
| | | } |
| | |
| | | return this.data; |
| | | } |
| | | |
| | | public R<T> setData(T data) { |
| | | public Result<T> setData(T data) { |
| | | this.data = data; |
| | | return this; |
| | | } |
| | |
| | | return this; |
| | | } |
| | | |
| | | public R<T> build() { |
| | | return new R(this.code, this.msg, this.data); |
| | | public Result<T> build() { |
| | | return new Result(this.code, this.msg, this.data); |
| | | } |
| | | |
| | | public String toString() { |