|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+package com.shinsoft.sto.model.system;
|
|
|
2
|
+
|
|
|
3
|
+import java.io.Serializable;
|
|
|
4
|
+
|
|
|
5
|
+/**
|
|
|
6
|
+ * 统一响应结果封装类
|
|
|
7
|
+ */
|
|
|
8
|
+public class ResultJSON implements Serializable {
|
|
|
9
|
+
|
|
|
10
|
+ private static final long serialVersionUID = 1L;
|
|
|
11
|
+
|
|
|
12
|
+ /**
|
|
|
13
|
+ * 状态码
|
|
|
14
|
+ */
|
|
|
15
|
+ private String code;
|
|
|
16
|
+
|
|
|
17
|
+ /**
|
|
|
18
|
+ * 消息
|
|
|
19
|
+ */
|
|
|
20
|
+ private String msg;
|
|
|
21
|
+
|
|
|
22
|
+ /**
|
|
|
23
|
+ * 数据
|
|
|
24
|
+ */
|
|
|
25
|
+ private Object data;
|
|
|
26
|
+
|
|
|
27
|
+ // 构造方法 - 兼容 JSONTools.java 中的使用
|
|
|
28
|
+ public ResultJSON() {
|
|
|
29
|
+ }
|
|
|
30
|
+
|
|
|
31
|
+ public ResultJSON(String code, String msg) {
|
|
|
32
|
+ this.code = code;
|
|
|
33
|
+ this.msg = msg;
|
|
|
34
|
+ }
|
|
|
35
|
+
|
|
|
36
|
+ public ResultJSON(String code, String msg, Object data) {
|
|
|
37
|
+ this.code = code;
|
|
|
38
|
+ this.msg = msg;
|
|
|
39
|
+ this.data = data;
|
|
|
40
|
+ }
|
|
|
41
|
+
|
|
|
42
|
+ // 兼容 int 类型 code 的构造方法(JSONTools.java 中使用了 int 参数)
|
|
|
43
|
+ public ResultJSON(int code, String msg) {
|
|
|
44
|
+ this.code = String.valueOf(code);
|
|
|
45
|
+ this.msg = msg;
|
|
|
46
|
+ }
|
|
|
47
|
+
|
|
|
48
|
+ public ResultJSON(int code, String msg, Object data) {
|
|
|
49
|
+ this.code = String.valueOf(code);
|
|
|
50
|
+ this.msg = msg;
|
|
|
51
|
+ this.data = data;
|
|
|
52
|
+ }
|
|
|
53
|
+
|
|
|
54
|
+ // 成功相关静态方法 - 使用 ResponseCodeMsg 常量
|
|
|
55
|
+ public static ResultJSON success() {
|
|
|
56
|
+ return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK);
|
|
|
57
|
+ }
|
|
|
58
|
+
|
|
|
59
|
+ public static ResultJSON success(String msg) {
|
|
|
60
|
+ return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, msg);
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ public static ResultJSON success(Object data) {
|
|
|
64
|
+ return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, ResponseCodeMsg.MSG_OK, data);
|
|
|
65
|
+ }
|
|
|
66
|
+
|
|
|
67
|
+ public static ResultJSON success(String msg, Object data) {
|
|
|
68
|
+ return new ResultJSON(ResponseCodeMsg.CODE_SUCCESS, msg, data);
|
|
|
69
|
+ }
|
|
|
70
|
+
|
|
|
71
|
+ // 错误相关静态方法
|
|
|
72
|
+ public static ResultJSON error() {
|
|
|
73
|
+ return new ResultJSON(ResponseCodeMsg.CODE_FAIL, ResponseCodeMsg.MSG_FAIL);
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ public static ResultJSON error(String msg) {
|
|
|
77
|
+ return new ResultJSON(ResponseCodeMsg.CODE_FAIL, msg);
|
|
|
78
|
+ }
|
|
|
79
|
+
|
|
|
80
|
+ public static ResultJSON error(String code, String msg) {
|
|
|
81
|
+ return new ResultJSON(code, msg);
|
|
|
82
|
+ }
|
|
|
83
|
+
|
|
|
84
|
+ public static ResultJSON error(String code, String msg, Object data) {
|
|
|
85
|
+ return new ResultJSON(code, msg, data);
|
|
|
86
|
+ }
|
|
|
87
|
+
|
|
|
88
|
+ // 兼容 int 类型 code 的错误方法
|
|
|
89
|
+ public static ResultJSON error(int code, String msg) {
|
|
|
90
|
+ return new ResultJSON(code, msg);
|
|
|
91
|
+ }
|
|
|
92
|
+
|
|
|
93
|
+ public static ResultJSON error(int code, String msg, Object data) {
|
|
|
94
|
+ return new ResultJSON(code, msg, data);
|
|
|
95
|
+ }
|
|
|
96
|
+
|
|
|
97
|
+ // Getter 和 Setter 方法
|
|
|
98
|
+ public String getCode() {
|
|
|
99
|
+ return code;
|
|
|
100
|
+ }
|
|
|
101
|
+
|
|
|
102
|
+ public void setCode(String code) {
|
|
|
103
|
+ this.code = code;
|
|
|
104
|
+ }
|
|
|
105
|
+
|
|
|
106
|
+ public String getMsg() {
|
|
|
107
|
+ return msg;
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ public void setMsg(String msg) {
|
|
|
111
|
+ this.msg = msg;
|
|
|
112
|
+ }
|
|
|
113
|
+
|
|
|
114
|
+ public Object getData() {
|
|
|
115
|
+ return data;
|
|
|
116
|
+ }
|
|
|
117
|
+
|
|
|
118
|
+ public void setData(Object data) {
|
|
|
119
|
+ this.data = data;
|
|
|
120
|
+ }
|
|
|
121
|
+
|
|
|
122
|
+ // 判断是否成功的方法
|
|
|
123
|
+ public boolean isSuccess() {
|
|
|
124
|
+ return ResponseCodeMsg.CODE_SUCCESS.equals(this.code);
|
|
|
125
|
+ }
|
|
|
126
|
+
|
|
|
127
|
+ @Override
|
|
|
128
|
+ public String toString() {
|
|
|
129
|
+ return "ResultJSON{" +
|
|
|
130
|
+ "code='" + code + '\'' +
|
|
|
131
|
+ ", msg='" + msg + '\'' +
|
|
|
132
|
+ ", data=" + data +
|
|
|
133
|
+ '}';
|
|
|
134
|
+ }
|
|
|
135
|
+}
|