xiangpei
2025-05-14 47cd9ecc0eff38ffe6b3b794b2bf197e958f4403
src/main/java/com/mindskip/xzs/base/RestResponse.java
@@ -1,12 +1,9 @@
package com.mindskip.xzs.base;
/**
 * @version 3.3.0
 * @description: The type Rest response.
 * Copyright (C), 2020-2021, 武汉思维跳跃科技有限公司
 * @date 2021/5/25 10:45
 */
public class RestResponse<T> {
import java.util.HashMap;
import java.util.Map;
public class RestResponse<T> extends HashMap<String, Object> {
    private int code;
    private String message;
    private T response;
@@ -18,8 +15,8 @@
     * @param message the message
     */
    public RestResponse(int code, String message) {
        this.code = code;
        this.message = message;
        this.put("code", code);
        this.put("message", message);
    }
    /**
@@ -29,10 +26,12 @@
     * @param message  the message
     * @param response the response
     */
    public RestResponse(int code, String message, T response) {
        this.code = code;
        this.message = message;
        this.response = response;
    public static RestResponse response(int code, String message, Object response) {
        RestResponse restResponse = new RestResponse();
        restResponse.put("code", code);
        restResponse.put("message", message);
        restResponse.put("response", response);
        return restResponse;
    }
    /**
@@ -65,7 +64,7 @@
     */
    public static <F> RestResponse<F> ok(F response) {
        SystemCode systemCode = SystemCode.OK;
        return new RestResponse<>(systemCode.getCode(), systemCode.getMessage(), response);
        return RestResponse.response(systemCode.getCode(), systemCode.getMessage(), response);
    }
    /**
@@ -74,16 +73,7 @@
     * @return the code
     */
    public int getCode() {
        return code;
    }
    /**
     * Sets code.
     *
     * @param code the code
     */
    public void setCode(int code) {
        this.code = code;
        return (int) this.get("code");
    }
    /**
@@ -92,17 +82,9 @@
     * @return the message
     */
    public String getMessage() {
        return message;
        return (String) this.get("message");
    }
    /**
     * Sets message.
     *
     * @param message the message
     */
    public void setMessage(String message) {
        this.message = message;
    }
    /**
     * Gets response.
@@ -110,18 +92,15 @@
     * @return the response
     */
    public T getResponse() {
        return response;
    }
    /**
     * Sets response.
     *
     * @param response the response
     */
    public void setResponse(T response) {
        this.response = response;
        return (T) this.get("response");
    }
    public RestResponse() {
    }
    @Override
    public RestResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}