package com.lilosoft.complex; public class Rest<T> { /** * 成功 */ public static final int SUCCESS = 1; /** * 失败 */ public static final int FAIL = -1; private T data; private Integer code; private String msg; private Object dict; public T getData() { return data; } public void setData(T data) { this.data = data; } public Integer getCode() { return code; } public void setCode(Integer code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public Object getDict() { return dict; } public void setDict(Object dict) { this.dict = dict; } public static <T> Rest<T> ok() { return restResult(null, SUCCESS, "操作成功"); } public static <T> Rest<T> ok(T data) { return restResult(data, SUCCESS, "操作成功"); } public static <T> Rest<T> ok(String msg) { return restResult(null, SUCCESS, msg); } public static <T> Rest<T> ok(String msg, T data) { return restResult(data, SUCCESS, msg); } public static <T> Rest<T> fail() { return restResult(null, FAIL, "操作失败"); } public static <T> Rest<T> fail(String msg) { return restResult(null, FAIL, msg); } public static <T> Rest<T> fail(T data) { return restResult(data, FAIL, "操作失败"); } public static <T> Rest<T> fail(String msg, T data) { return restResult(data, FAIL, msg); } public static <T> Rest<T> fail(int code, String msg) { return restResult(null, code, msg); } private static <T> Rest<T> restResult(T data, int code, String msg) { Rest<T> rest = new Rest<>(); rest.setCode(code); rest.setData(data); rest.setMsg(msg); return rest; } }