luodangjia
2024-11-28 06f455915bb9d11caa8829942f9007809ee9ae3d
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/AjaxResult.java
@@ -4,24 +4,28 @@
import java.util.Objects;
import com.ruoyi.common.core.constant.HttpStatus;
import com.ruoyi.common.core.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
 * 操作消息提醒
 * 
 * @author ruoyi
 */
public class AjaxResult<T> extends HashMap<String, Object>
{
    private static final long serialVersionUID = 1L;
@ApiModel
public class AjaxResult<T> extends HashMap {
    /** 状态码 */
    public static final String CODE_TAG = "code";
    @ApiModelProperty("状态码")
    private int code;
    /** 返回内容 */
    public static final String MSG_TAG = "msg";
    @ApiModelProperty("描述内容")
    private String msg = "";
    /** 数据对象 */
    public static final String DATA_TAG = "data";
    @ApiModelProperty("结果集")
    private T data;
    /**
     * 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
@@ -38,8 +42,8 @@
     */
    public AjaxResult(int code, String msg)
    {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        this.code = code;
        this.msg = msg;
    }
    /**
@@ -49,12 +53,12 @@
     * @param msg 返回内容
     * @param data 数据对象
     */
    public AjaxResult(int code, String msg, Object data)
    public AjaxResult(int code, String msg, T data)
    {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        this.code = code;
        this.msg = msg;
        if (StringUtils.isNotNull(data)) {
            super.put(DATA_TAG, data);
            this.data = data;
        }
    }
@@ -181,7 +185,7 @@
     */
    public boolean isSuccess()
    {
        return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG));
        return Objects.equals(HttpStatus.SUCCESS, this.code);
    }
    /**
@@ -195,19 +199,4 @@
    }
    /**
     * 方便链式调用
     *
     * @param key
     * @param value
     * @return
     */
    @Override
    public AjaxResult put(String key, Object value)
    {
        super.put(key, value);
        return this;
    }
}