xiangpei
2025-05-14 47cd9ecc0eff38ffe6b3b794b2bf197e958f4403
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.mindskip.xzs.base;
 
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;
 
    /**
     * Instantiates a new Rest response.
     *
     * @param code    the code
     * @param message the message
     */
    public RestResponse(int code, String message) {
        this.put("code", code);
        this.put("message", message);
    }
 
    /**
     * Instantiates a new Rest response.
     *
     * @param code     the code
     * @param message  the message
     * @param response the 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;
    }
 
    /**
     * Fail rest response.
     *
     * @param code the code
     * @param msg  the msg
     * @return the rest response
     */
    public static RestResponse fail(Integer code, String msg) {
        return new RestResponse<>(code, msg);
    }
 
    /**
     * Ok rest response.
     *
     * @return the rest response
     */
    public static RestResponse ok() {
        SystemCode systemCode = SystemCode.OK;
        return new RestResponse<>(systemCode.getCode(), systemCode.getMessage());
    }
 
    /**
     * Ok rest response.
     *
     * @param <F>      the type parameter
     * @param response the response
     * @return the rest response
     */
    public static <F> RestResponse<F> ok(F response) {
        SystemCode systemCode = SystemCode.OK;
        return RestResponse.response(systemCode.getCode(), systemCode.getMessage(), response);
    }
 
    /**
     * Gets code.
     *
     * @return the code
     */
    public int getCode() {
        return (int) this.get("code");
    }
 
    /**
     * Gets message.
     *
     * @return the message
     */
    public String getMessage() {
        return (String) this.get("message");
    }
 
 
    /**
     * Gets response.
     *
     * @return the response
     */
    public T getResponse() {
        return (T) this.get("response");
    }
 
    public RestResponse() {
    }
 
    @Override
    public RestResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}