|
@@ -0,0 +1,74 @@
|
|
|
|
|
+package com.sckw.core.web.response;
|
|
|
|
|
+
|
|
|
|
|
+import com.sckw.core.web.constant.HttpStatus;
|
|
|
|
|
+import lombok.*;
|
|
|
|
|
+import lombok.experimental.Accessors;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.Serial;
|
|
|
|
|
+import java.io.Serializable;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@ToString
|
|
|
|
|
+@NoArgsConstructor
|
|
|
|
|
+@AllArgsConstructor
|
|
|
|
|
+@Accessors(chain = true)
|
|
|
|
|
+public class ApiResult<T> implements Serializable {
|
|
|
|
|
+
|
|
|
|
|
+ @Serial
|
|
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
|
|
+
|
|
|
|
|
+ @Getter
|
|
|
|
|
+ @Setter
|
|
|
|
|
+ private String msg;
|
|
|
|
|
+ @Getter
|
|
|
|
|
+ @Setter
|
|
|
|
|
+ private Boolean status;
|
|
|
|
|
+ @Getter
|
|
|
|
|
+ @Setter
|
|
|
|
|
+ private String sign;
|
|
|
|
|
+ @Getter
|
|
|
|
|
+ @Setter
|
|
|
|
|
+ private T data;
|
|
|
|
|
+
|
|
|
|
|
+ public static <T> ApiResult<T> ok() {
|
|
|
|
|
+ return restResult(null, true, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static <T> ApiResult<T> ok(T data) {
|
|
|
|
|
+ return restResult(data, true, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static <T> ApiResult<T> ok(T data, String msg) {
|
|
|
|
|
+ return restResult(data, true, msg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static <T> ApiResult<T> failed() {
|
|
|
|
|
+ return restResult(null, false, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static <T> ApiResult<T> failed(String msg) {
|
|
|
|
|
+ return restResult(null, false, msg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static <T> ApiResult<T> failed(T data) {
|
|
|
|
|
+ return restResult(data, false, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static <T> ApiResult<T> failed(T data, String msg) {
|
|
|
|
|
+ return restResult(data, false, msg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static <T> ApiResult<T> failed(T data, String msg, int code) {
|
|
|
|
|
+ return restResult(data, false, msg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static <T> ApiResult<T> restResult(T data, Boolean status, String msg) {
|
|
|
|
|
+ ApiResult<T> apiResult = new ApiResult<>();
|
|
|
|
|
+ apiResult.setStatus(status);
|
|
|
|
|
+ apiResult.setData(data);
|
|
|
|
|
+ apiResult.setMsg(msg);
|
|
|
|
|
+ return apiResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|