RuoYi
2023-06-24 1d7bdf4549224951674e5ad28e314848d608e09c
src/main/java/com/ruoyi/framework/web/domain/AjaxResult.java
@@ -1,6 +1,7 @@
package com.ruoyi.framework.web.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;
    }
}