ソースを参照

cn.reghao.jutil.web.WebResult add fallback method

reghao 8 ヶ月 前
コミット
b8a6b56b7b
1 ファイル変更12 行追加0 行削除
  1. 12 0
      web/src/main/java/cn/reghao/jutil/web/WebResult.java

+ 12 - 0
web/src/main/java/cn/reghao/jutil/web/WebResult.java

@@ -31,6 +31,13 @@ public class WebResult<T> {
         this.requestId = ServletUtil.getHeader("x-request-id");
     }
 
+    private WebResult(String msg) {
+        this.code = ResultStatus.SUCCESS.getCode();
+        this.msg = msg;
+        this.timestamp = System.currentTimeMillis();
+        this.requestId = "";
+    }
+
     public int getCode() {
         return code;
     }
@@ -100,4 +107,9 @@ public class WebResult<T> {
         WebResult<T> webBody = new WebResult<>(ResultStatus.ERROR.getCode(), msg);
         return JsonConverter.objectToJson(webBody);
     }
+
+    public static <T> String fallback(String msg) {
+        WebResult<T> webBody = new WebResult<>(msg);
+        return JsonConverter.objectToJson(webBody);
+    }
 }