AjaxResultTv.java
2.77 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
package com.huaheng.framework.web.domain;
import java.io.Serializable;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 操作消息提醒
*
* @author huaheng
*/
@Data
public class AjaxResultTv<T> implements Serializable
{
private static final long serialVersionUID = 1L;
@JSONField(name = "Code")
public int Code;
@JSONField(name = "Message")
private String Message;
@JSONField(name = "Result")
private T Result;
public Boolean hasErr(){
if(Code == RetCode.SUCCESS.getValue()){
return false;
}else {
return true;
}
}
public AjaxResultTv<T> setCode(RetCode retCode) {
this.Code = retCode.getValue();
return this;
}
@Override
public String toString() {
return JSON.toJSONString(this);
}
/**
* 响应返回结果
*
* @param succeed 是否成功
* @return 操作结果
*/
public static AjaxResultTv toAjax(boolean succeed)
{
return succeed ? success("成功") : error("失败");
}
/**
* 返回成功消息
*/
public static AjaxResultTv success(String message)
{
AjaxResultTv ajaxResultTv= new AjaxResultTv<>();
ajaxResultTv.setCode(RetCode.SUCCESS).setMessage(message);
return ajaxResultTv;
}
/**
* 返回成功消息
*/
public static AjaxResultTv success()
{
AjaxResultTv ajaxResultTv= new AjaxResultTv<>();
ajaxResultTv.setCode(RetCode.SUCCESS).setMessage("成功");
return ajaxResultTv;
}
/**
* 返回成功消息
*/
public static <T> AjaxResultTv<T> success(T data)
{
AjaxResultTv ajaxResultTv= new AjaxResultTv<T>();
ajaxResultTv.setCode(RetCode.SUCCESS).setMessage("成功");
ajaxResultTv.setResult(data);
return ajaxResultTv;
}
/**
* 返回成功消息
*/
public static <T> AjaxResultTv<T> success(String message, T data)
{
AjaxResultTv ajaxResultTv= new AjaxResultTv<T>();
ajaxResultTv.setCode(RetCode.SUCCESS).setMessage(message);
ajaxResultTv.setResult(data);
return ajaxResultTv;
}
/**
* 返回失败消息
*/
public static AjaxResultTv error(String message)
{
AjaxResultTv ajaxResultTv= new AjaxResultTv<>();
ajaxResultTv.setCode(RetCode.SUCCESS).setMessage(message);
return ajaxResultTv;
}
/**
* 返回失败消息
*/
public static <T> AjaxResultTv<T> error()
{
AjaxResultTv ajaxResultTv= new AjaxResultTv<T>();
ajaxResultTv.setCode(RetCode.FAIL).setMessage("失败");
return ajaxResultTv;
}
}