puzhibing
2023-12-04 3ad6b6ba2ba56fc0bcd2130e47190779c6e15acc
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.dsh.course.util.httpClinet;
 
/**
 * 定义统一返回对象
 */
public class ResultUtil<T> {
 
    public static final Integer SUCCESS = 200;
 
    public static final Integer PARAM_ERROR = 300;
 
    public static final Integer RUNTIME_ERROR = 400;
 
    public static final Integer ERROR = 500;
 
    public static final String Token = "Token失效";
 
    private Integer status;//状态码
 
    private Integer code;//备用状态码
 
    private String msg;//返回说明
 
    private T data;//返回数据
 
    private String str;//存储单个字符串值
 
 
    public Integer getStatus() {
        return status;
    }
 
    public String getMsg() {
        return msg;
    }
 
    public T getData() {
        return data;
    }
 
    public String getStr() {
        return str;
    }
 
    public Integer getCode() {
        return code;
    }
 
    public ResultUtil(Integer status, Integer code, String msg) {
        this.status = status;
        this.code = code;
        this.msg = msg;
    }
 
    private ResultUtil(Integer status, Integer code, String msg, T data) {
        this.status = status;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
 
    public ResultUtil(Integer status, Integer code, String msg, T data, String str) {
        this.status = status;
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.str = str;
    }
 
    private ResultUtil(Integer status, Integer code, String msg, String str) {
        this.status = status;
        this.code = code;
        this.msg = msg;
        this.str = str;
    }
 
 
    public static <T> ResultUtil<T> getResult(Integer status, Integer code, String msg){
        return new ResultUtil<>(status, code, msg);
    }
 
    public static <T> ResultUtil<T> getResult(Integer status, Integer code, String msg, T data){
        return new ResultUtil<>(status, code, msg, data);
    }
 
    public static <T> ResultUtil<T> getResult(Integer status, Integer code, String msg, T data, String str){
        return new ResultUtil<>(status, code, msg, data, str);
    }
 
    /**
     * 错误信息
     * @return
     */
    public static ResultUtil error(String mag){
        return ResultUtil.getResult(ResultUtil.ERROR, ResultUtil.ERROR, mag);
    }
 
    /**
     * 错误信息
     * @return
     */
    public static <T> ResultUtil <T> error(String mag, T obj){
        return ResultUtil.getResult(ResultUtil.ERROR, ResultUtil.ERROR, mag, obj);
    }
 
    /**
     * token失效
     * @return
     */
    public static ResultUtil tokenErr(){
        return ResultUtil.getResult(ResultUtil.ERROR, ResultUtil.ERROR, ResultUtil.Token);
    }
 
    /**
     * token失效
     * @return
     */
    public static ResultUtil tokenErr(String msg){
        return ResultUtil.getResult(ResultUtil.ERROR, ResultUtil.ERROR, msg);
    }
 
    /**
     * 参数异常
     * @return
     */
    public static  ResultUtil paranErr(){
        return ResultUtil.getResult(ResultUtil.PARAM_ERROR, ResultUtil.PARAM_ERROR, "参数异常");
    }
 
    /**
     * 参数异常
     * @return
     */
    public static <T> ResultUtil<T> paranErr(T data){
        return ResultUtil.getResult(ResultUtil.PARAM_ERROR, ResultUtil.PARAM_ERROR, "参数异常", data);
    }
 
    /**
     * 运行异常
     * @return
     */
    public static ResultUtil runErr(){
        return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, ResultUtil.RUNTIME_ERROR, "服务器运行异常");
    }
 
 
    /**
     * 运行异常
     * @return
     */
    public static <T>ResultUtil<T> runErr(T data){
        return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, ResultUtil.RUNTIME_ERROR, "服务器运行异常", data);
    }
 
 
    /**
     * 返回成功
     * @param
     * @return
     */
    public static ResultUtil success(){
        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, "成功");
    }
 
 
    /**
     * 返回成功
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResultUtil<T> success(T data){
        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, "成功", data);
    }
 
    /**
     * 返回成功
     * @param data
     * @param str
     * @param <T>
     * @return
     */
    public static <T> ResultUtil<T> success(T data, String str){
        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, "成功", data, str);
    }
 
    public static <T> ResultUtil<T> success(String msg, T data){
        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, msg, data);
    }
 
    public static <T> ResultUtil<T> success(String msg, T data, String str){
        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, msg, data, str);
    }
 
}