提交 | 用户 | age
|
5c5945
|
1 |
package com.hx.resultTool; |
E |
2 |
|
1c6e57
|
3 |
import com.hx.exception.TipsException; |
F |
4 |
|
5c5945
|
5 |
import java.io.Serializable; |
E |
6 |
|
|
7 |
/** |
|
8 |
* 统一返回格式 |
|
9 |
* @author chenjiahe |
|
10 |
* @Data: 2020-06-20 |
|
11 |
*/ |
|
12 |
public class Result implements Serializable { |
|
13 |
|
|
14 |
private static final long serialVersionUID = -3948389268046368059L; |
|
15 |
|
|
16 |
private String code; |
|
17 |
|
|
18 |
private String msg; |
|
19 |
|
|
20 |
private Object data; |
|
21 |
|
|
22 |
public Result() {} |
|
23 |
|
|
24 |
public Result(String code, String msg) { |
|
25 |
this.code = code; |
|
26 |
this.msg = msg; |
|
27 |
} |
|
28 |
|
|
29 |
public static Result success() { |
|
30 |
Result Result = new Result(); |
|
31 |
Result.setCode(ResponseCode.SUCCESS); |
|
32 |
Result.setMsg("SUCCESS"); |
|
33 |
return Result; |
|
34 |
} |
|
35 |
|
|
36 |
public static Result success(Object data) { |
|
37 |
Result Result = new Result(); |
|
38 |
Result.setCode(ResponseCode.SUCCESS); |
|
39 |
Result.setData(data); |
|
40 |
Result.setMsg("SUCCESS"); |
|
41 |
return Result; |
|
42 |
} |
|
43 |
|
|
44 |
public static Result failure(String code, String msg) { |
|
45 |
Result Result = new Result(); |
|
46 |
Result.setCode(code); |
|
47 |
Result.setMsg(msg); |
|
48 |
return Result; |
|
49 |
} |
|
50 |
|
|
51 |
public static Result failure(String code, String msg, Object data) { |
|
52 |
Result Result = new Result(); |
|
53 |
Result.setCode(code); |
|
54 |
Result.setMsg(msg); |
|
55 |
Result.setData(data); |
|
56 |
return Result; |
|
57 |
} |
|
58 |
|
32668c
|
59 |
/**校验返回码*/ |
C |
60 |
public Boolean checkCode(){ |
c5817f
|
61 |
if(ResponseCode.SUCCESS.equals(code)){ |
C |
62 |
return true; |
32668c
|
63 |
} |
c5817f
|
64 |
return false; |
32668c
|
65 |
} |
C |
66 |
|
1c6e57
|
67 |
/**校验返回码,进行错误提示*/ |
F |
68 |
public void checkTips(){ |
|
69 |
if(!ResponseCode.SUCCESS.equals(code)){ |
|
70 |
throw new TipsException("请求失败:"+this.code+","+this.msg); |
|
71 |
} |
|
72 |
} |
|
73 |
|
5c5945
|
74 |
/*******************************************************************************/ |
E |
75 |
|
|
76 |
public String getCode() { |
|
77 |
return this.code; |
|
78 |
} |
|
79 |
|
|
80 |
public void setCode(final String code) { |
|
81 |
this.code = code; |
|
82 |
} |
|
83 |
|
|
84 |
public String getMsg() { |
|
85 |
return this.msg; |
|
86 |
} |
|
87 |
|
|
88 |
public void setMsg(final String msg) { |
|
89 |
this.msg = msg; |
|
90 |
} |
|
91 |
|
|
92 |
public Object getData() { |
|
93 |
return this.data; |
|
94 |
} |
|
95 |
|
|
96 |
public void setData(final Object data) { |
|
97 |
this.data = data; |
|
98 |
} |
|
99 |
|
|
100 |
} |
|
101 |
|