ResultObject.java
2.73 KB
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
package cn.com.glsx.admin.modules.model;
import com.alibaba.fastjson.JSON;
import java.io.Serializable;
/**
* 调用同步信息接口时包活干返回对象
* @author yuanlin
* @version 1.1.0
* @history created by yuanlin
* */
public class ResultObject implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int code;//返回码 200成功,500系统异常
private String message;//消息
private Object data;//数据
private String error; //服务器异常信息
public ResultObject() {
}
/**
* @param code 返回码
*/
public ResultObject(int code) {
super();
this.code = code;
}
/**
* @param code 返回码
* @param message 返回信息
*/
public ResultObject(int code, String message) {
super();
this.code = code;
this.message = message;
}
/**
* @param code 返回码
* @param data 返回数据
*/
public ResultObject(int code, Object data) {
super();
this.code = code;
this.data = data;
}
/**
* @param code 返回码
* @param message 返回信息
* @param data 返回数据
*/
public ResultObject(int code, String message, Object data) {
super();
this.code = code;
this.message = message;
this.data = data;
}
public ResultObject message(String msg) {
this.message = msg;
return this;
}
public static ResultObject err(String returnCode) {
ResultObject resultEntity = new ResultObject();
resultEntity.setCode(Integer.valueOf(returnCode));
resultEntity.setMessage("fail");
return resultEntity;
}
/**
* @param code 返回码
* @param message 返回信息
* @param data 返回数据
* @param error 服务器异常信息
*/
public ResultObject(int code, String message, Object data, String error) {
super();
this.code = code;
this.message = message;
this.data = data;
this.error = error;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public static void main(String[] args) {
ResultObject json = new ResultObject(200, "123", new int[]{1, 2, 3}, "系统异常");
System.out.println(JSON.toJSONString(json));
}
public static ResultObject create(int success, Object response) {
return new ResultObject(success);
}
@Override
public String toString() {
return "ResultObject{" +
"code=" + code +
", message='" + message + '\'' +
", data=" + data +
", error='" + error + '\'' +
'}';
}
}