From 259dc6772814427bda8c6c39eea02f9e1277ff07 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期三, 05 六月 2024 12:30:43 +0800
Subject: [PATCH] 优化数据权限代码
---
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java | 76 ++++++++++++++++++++++++++++++++++++--
1 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java
index b26e066..42dcbcd 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java
@@ -1,6 +1,7 @@
package com.ruoyi.common.core.domain;
import java.util.HashMap;
+import java.util.Objects;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.utils.StringUtils;
@@ -102,9 +103,32 @@
}
/**
+ * 返回警告消息
+ *
+ * @param msg 返回内容
+ * @return 警告消息
+ */
+ public static AjaxResult warn(String msg)
+ {
+ return AjaxResult.warn(msg, null);
+ }
+
+ /**
+ * 返回警告消息
+ *
+ * @param msg 返回内容
+ * @param data 数据对象
+ * @return 警告消息
+ */
+ public static AjaxResult warn(String msg, Object data)
+ {
+ return new AjaxResult(HttpStatus.WARN, msg, data);
+ }
+
+ /**
* 返回错误消息
*
- * @return
+ * @return 错误消息
*/
public static AjaxResult error()
{
@@ -115,7 +139,7 @@
* 返回错误消息
*
* @param msg 返回内容
- * @return 警告消息
+ * @return 错误消息
*/
public static AjaxResult error(String msg)
{
@@ -127,7 +151,7 @@
*
* @param msg 返回内容
* @param data 数据对象
- * @return 警告消息
+ * @return 错误消息
*/
public static AjaxResult error(String msg, Object data)
{
@@ -139,10 +163,54 @@
*
* @param code 状态码
* @param msg 返回内容
- * @return 警告消息
+ * @return 错误消息
*/
public static AjaxResult error(int code, String msg)
{
return new AjaxResult(code, msg, null);
}
+
+ /**
+ * 是否为成功消息
+ *
+ * @return 结果
+ */
+ public boolean isSuccess()
+ {
+ return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG));
+ }
+
+ /**
+ * 是否为警告消息
+ *
+ * @return 结果
+ */
+ public boolean isWarn()
+ {
+ return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG));
+ }
+
+ /**
+ * 是否为错误消息
+ *
+ * @return 结果
+ */
+ public boolean isError()
+ {
+ return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG));
+ }
+
+ /**
+ * 方便链式调用
+ *
+ * @param key 键
+ * @param value 值
+ * @return 数据对象
+ */
+ @Override
+ public AjaxResult put(String key, Object value)
+ {
+ super.put(key, value);
+ return this;
+ }
}
--
Gitblit v1.9.2