1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| public class Resp<T> {
private int code=200; private String msg="success"; private T data;
private Resp(int code,String msg,T data){ this.code=code; this.msg=msg; this.data=data; }
public static <T> Resp success(T data){ Resp<T> resp = new Resp<>(200, "success", data); return resp; }
public static <T> Resp success(String msg,T data){ Resp resp = new Resp(200, msg, data); return resp; }
public static <T> Resp error(AppExceptionCodeMsg appExceptionCodeMsg){ Resp resp = new Resp(appExceptionCodeMsg.getCode(), appExceptionCodeMsg.getMsg(), null); return resp; }
public static <T> Resp error(int code,String msg){ Resp resp = new Resp(code, msg, null); return resp; }
public int getCode(){ return code; }
public String getMsg(){ return msg; }
public String toJsonString() { return JSON.toJSONString(this); } @Override public String toString() { return "Resp{" + "code=" + code + ", msg='" + msg + '\'' + ", data=" + data + '}'; }
}
|