import lombok.*; /** * 响应信息主体 */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter public class R<T> { private static Integer successCode = 200; private static Integer failCode = 500; private static String successMsg = "SUCCESS"; private static String errorMsg = "ERROR"; private int code; private String msg; private T data; public static <T> R<T> ok() { return newResult(successCode, successMsg, null); } public static <T> R<T> ok(String msg) { return newResult(successCode, msg, null); } public static <T> R<T> ok(T data) { return newResult(successCode, successMsg, data); } public static <T> R<T> ok(String msg, T data) { return newResult(successCode, msg, data); } public static <T> R<T> failed() { return newResult(failCode, errorMsg, null); } public static <T> R<T> failed(String msg) { return newResult(failCode, msg, null); } public static <T> R<T> failed(T data) { return newResult(failCode, errorMsg, data); } public static <T> R<T> failed(String msg, T data) { return newResult(failCode, msg, data); } private static <T> R<T> newResult(int code, String msg, T data) { R<T> result = new R<>(); result.setCode(code); result.setMsg(msg); result.setData(data); return result; } }
标签:,return,static,msg,newResult,data,public From: https://www.cnblogs.com/mingruifeng/p/17717605.html