fuliqi
2024-06-03 9d72545e1ebb81d80d11b6a6e683e5581cc322fc
src/main/java/com/ycl/jxkg/base/Result.java
@@ -1,15 +1,20 @@
package com.ycl.jxkg.base;
import java.util.HashMap;
/**
 * @version 3.3.0
 * @description: The type Rest response.
 * Copyright (C), 2020-2024, 武汉思维跳跃科技有限公司
 * @date 2021/5/25 10:45
 */
public class Result<T> {
public class Result<T> extends HashMap<String, Object> {
    private int code;
    private String message;
    private T response;
    private T data;
    public Result() {
    }
    /**
     * Instantiates a new Rest response.
@@ -29,10 +34,12 @@
     * @param message  the message
     * @param response the response
     */
    public Result(int code, String message, T response) {
        this.code = code;
        this.message = message;
        this.response = response;
    public static Result response(int code, String message, Object response) {
        Result restResponse = new Result();
        restResponse.put("code", code);
        restResponse.put("message", message);
        restResponse.put("data", response);
        return restResponse;
    }
    /**
@@ -65,7 +72,7 @@
     */
    public static <F> Result<F> ok(F response) {
        SystemCode systemCode = SystemCode.OK;
        return new Result<>(systemCode.getCode(), systemCode.getMessage(), response);
        return Result.response(systemCode.getCode(), systemCode.getMessage(), response);
    }
    /**
@@ -110,7 +117,7 @@
     * @return the response
     */
    public T getResponse() {
        return response;
        return data;
    }
    /**
@@ -119,6 +126,22 @@
     * @param response the response
     */
    public void setResponse(T response) {
        this.response = response;
        this.data = response;
    }
    @Override
    public Result<T> put(String key, Object value) {
        super.put(key, value);
        return this;
    }
    public Result data(Object data) {
        super.put("data", data);
        return this;
    }
    public Result total(Long total) {
        super.put("total", total);
        return this;
    }
}