AjaxResultWCS.java
3.49 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
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
package com.huaheng.framework.web.domain;
import com.alibaba.fastjson.JSON;
import java.io.Serializable;
/**
* 操作消息提醒
*
* @author huaheng
*/
public class AjaxResultWCS<T> implements Serializable
{
private static final long serialVersionUID = 1L;
public int code;
private String message;
private String errorCode;
private T data;
private String msg;
public Boolean hasErr(){
if(code == RetCode.SUCCESS.getValue()){
return false;
}else {
return true;
}
}
public AjaxResultWCS<T> setCode(RetCode retCode) {
this.code = retCode.getValue();
return this;
}
public int getCode() {
return code;
}
public AjaxResultWCS<T> setCode(int code) {
this.code = code;
return this;
}
public String getMsg() {
return msg;
}
public AjaxResultWCS<T> setMsg(String msg) {
this.msg = msg;
return this;
}
public String getMessage() {
return message;
}
public AjaxResultWCS<T> setMessage(String msg) {
this.message = msg;
return this;
}
public T getData() {
return data;
}
public AjaxResultWCS<T> setData(T data) {
this.data = data;
return this;
}
@Override
public String toString() {
return JSON.toJSONString(this);
}
/**
* 响应返回结果
*
* @param succeed 是否成功
* @return 操作结果
*/
public static AjaxResultWCS toAjax(boolean succeed)
{
return succeed ? success("成功") : error("失败");
}
/**
* 返回成功消息
*/
public static AjaxResultWCS success(String message)
{
return new AjaxResultWCS<>().setCode(RetCode.SUCCESS).setMessage(message);
}
/**
* 返回成功消息
*/
public static AjaxResultWCS success()
{
return new AjaxResultWCS<>().setCode(RetCode.SUCCESS).setMessage("成功");
}
/**
* 返回成功消息
*/
public static <T> AjaxResultWCS<T> success(T data)
{
return new AjaxResultWCS<T>().setCode(RetCode.SUCCESS).setMessage("成功").setData(data);
}
/**
* 返回成功消息
*/
public static <T> AjaxResultWCS<T> success(String message, T data)
{
return new AjaxResultWCS<T>().setCode(RetCode.SUCCESS).setMessage(message).setData(data);
}
/**
* 返回失败消息
*/
public static AjaxResultWCS error(String message)
{
return new AjaxResultWCS<>().setCode(RetCode.FAIL).setMessage(message);
}
/**
* 返回失败消息
*/
public static <T> AjaxResultWCS<T> error(String message, T data)
{
return new AjaxResultWCS<T>().setCode(RetCode.FAIL).setMessage(message).setData(data);
}
/**
* 返回失败消息
*/
public static <T> AjaxResultWCS<T> error()
{
return new AjaxResultWCS<T>().setCode(RetCode.FAIL).setMessage("失败");
}
/**
* 返回消息
*/
public static <T> AjaxResultWCS<T> setResult(RetCode retCode, String message, T data)
{
return new AjaxResultWCS<T>().setCode(retCode).setMessage(message).setData(data);
}
/**
* 返回响应码和消息
* @param code
* @param message
* @param <T>
* @return
*/
public static <T> AjaxResultWCS<T> setResultCS(int code, String message)
{
return new AjaxResultWCS<T>().setCode(code).setMessage(message);
}
}