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