|
|
@@ -0,0 +1,74 @@
|
|
|
+package com.sckw.core.utils;
|
|
|
+
|
|
|
+import lombok.*;
|
|
|
+import lombok.experimental.Accessors;
|
|
|
+
|
|
|
+import java.io.Serial;
|
|
|
+import java.io.Serializable;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author xcq
|
|
|
+ * @date 2022年06月14日 13:41
|
|
|
+ */
|
|
|
+@ToString
|
|
|
+@NoArgsConstructor
|
|
|
+@AllArgsConstructor
|
|
|
+@Accessors(chain = true)
|
|
|
+public class R<T> implements Serializable {
|
|
|
+ @Serial
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+ /**
|
|
|
+ * 200-成功 102-失败
|
|
|
+ */
|
|
|
+ @Getter
|
|
|
+ @Setter
|
|
|
+ private int code;
|
|
|
+
|
|
|
+ @Getter
|
|
|
+ @Setter
|
|
|
+ private String msg;
|
|
|
+
|
|
|
+ @Getter
|
|
|
+ @Setter
|
|
|
+ private T data;
|
|
|
+
|
|
|
+ public static <T> R<T> ok() {
|
|
|
+ return restResult(null, 200, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> R<T> ok(T data) {
|
|
|
+ return restResult(data, 200, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> R<T> ok(T data, String msg) {
|
|
|
+ return restResult(data, 200, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> R<T> failed() {
|
|
|
+ return restResult(null, 102, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> R<T> failed(String msg) {
|
|
|
+ return restResult(null, 102, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> R<T> failed(T data) {
|
|
|
+ return restResult(data, 102, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> R<T> failed(T data, String msg) {
|
|
|
+ return restResult(data, 102, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> R<T> failed(T data, String msg, int code) {
|
|
|
+ return restResult(data, code, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static <T> R<T> restResult(T data, int code, String msg) {
|
|
|
+ R<T> apiResult = new R<>();
|
|
|
+ apiResult.setCode(code);
|
|
|
+ apiResult.setData(data);
|
|
|
+ apiResult.setMsg(msg);
|
|
|
+ return apiResult;
|
|
|
+ }
|
|
|
+}
|