From b6dbe7b5a5727d048724d9e86b2519cf599ded41 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期一, 31 十月 2022 10:33:29 +0800 Subject: [PATCH] update 优化 新增返回警告消息提示 --- ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java | 47 +++++++++++++++++++++++++++++++++++------------ 1 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java index 8fa4a64..381a6f6 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java @@ -1,7 +1,6 @@ package com.ruoyi.common.core.domain; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; +import com.ruoyi.common.constant.HttpStatus; import lombok.Data; import lombok.NoArgsConstructor; @@ -14,7 +13,6 @@ */ @Data @NoArgsConstructor -@ApiModel("璇锋眰鍝嶅簲瀵硅薄") public class R<T> implements Serializable { private static final long serialVersionUID = 1L; @@ -28,33 +26,30 @@ */ public static final int FAIL = 500; - @ApiModelProperty("娑堟伅鐘舵�佺爜") private int code; - @ApiModelProperty("娑堟伅鍐呭") private String msg; - @ApiModelProperty("鏁版嵁瀵硅薄") private T data; public static <T> R<T> ok() { - return restResult(null, SUCCESS, null); + return restResult(null, SUCCESS, "鎿嶄綔鎴愬姛"); } public static <T> R<T> ok(T data) { - return restResult(data, SUCCESS, null); + return restResult(data, SUCCESS, "鎿嶄綔鎴愬姛"); } public static <T> R<T> ok(String msg) { return restResult(null, SUCCESS, msg); } - public static <T> R<T> ok(T data, String msg) { + public static <T> R<T> ok(String msg, T data) { return restResult(data, SUCCESS, msg); } public static <T> R<T> fail() { - return restResult(null, FAIL, null); + return restResult(null, FAIL, "鎿嶄綔澶辫触"); } public static <T> R<T> fail(String msg) { @@ -62,15 +57,36 @@ } public static <T> R<T> fail(T data) { - return restResult(data, FAIL, null); + return restResult(data, FAIL, "鎿嶄綔澶辫触"); } - public static <T> R<T> fail(T data, String msg) { + public static <T> R<T> fail(String msg, T data) { return restResult(data, FAIL, msg); } public static <T> R<T> fail(int code, String msg) { return restResult(null, code, msg); + } + + /** + * 杩斿洖璀﹀憡娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @return 璀﹀憡娑堟伅 + */ + public static <T> R<T> warn(String msg) { + return restResult(null, HttpStatus.WARN, msg); + } + + /** + * 杩斿洖璀﹀憡娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @param data 鏁版嵁瀵硅薄 + * @return 璀﹀憡娑堟伅 + */ + public static <T> R<T> warn(String msg, T data) { + return restResult(data, HttpStatus.WARN, msg); } private static <T> R<T> restResult(T data, int code, String msg) { @@ -81,4 +97,11 @@ return r; } + public static <T> Boolean isError(R<T> ret) { + return !isSuccess(ret); + } + + public static <T> Boolean isSuccess(R<T> ret) { + return R.SUCCESS == ret.getCode(); + } } -- Gitblit v1.9.3