Commit fbaa1a53f5766ee4f10ce39c5cf50c7527ec13c6
1 parent
445c2015
返回结果支持泛型
Showing
1 changed file
with
137 additions
and
110 deletions
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/common/api/vo/Result.java
1 | -package org.jeecg.common.api.vo; | |
2 | - | |
3 | -import java.io.Serializable; | |
4 | -import io.swagger.annotations.ApiModel; | |
5 | -import io.swagger.annotations.ApiModelProperty; | |
6 | -import org.jeecg.common.constant.CommonConstant; | |
7 | -import lombok.Data; | |
8 | - | |
9 | -/** | |
10 | - * 接口返回数据格式 | |
11 | - * @author scott | |
12 | - * @email jeecgos@163.com | |
13 | - * @date 2019年1月19日 | |
14 | - */ | |
15 | -@Data | |
16 | -@ApiModel(value="接口返回对象", description="接口返回对象") | |
17 | -public class Result<T> implements Serializable { | |
18 | - | |
19 | - private static final long serialVersionUID = 1L; | |
20 | - | |
21 | - /** | |
22 | - * 成功标志 | |
23 | - */ | |
24 | - @ApiModelProperty(value = "成功标志") | |
25 | - private boolean success = true; | |
26 | - | |
27 | - /** | |
28 | - * 返回处理消息 | |
29 | - */ | |
30 | - @ApiModelProperty(value = "返回处理消息") | |
31 | - private String message = "操作成功!"; | |
32 | - | |
33 | - /** | |
34 | - * 返回代码 | |
35 | - */ | |
36 | - @ApiModelProperty(value = "返回代码") | |
37 | - private Integer code = 0; | |
38 | - | |
39 | - /** | |
40 | - * 返回数据对象 data | |
41 | - */ | |
42 | - @ApiModelProperty(value = "返回数据对象") | |
43 | - private T result; | |
44 | - | |
45 | - /** | |
46 | - * 时间戳 | |
47 | - */ | |
48 | - @ApiModelProperty(value = "时间戳") | |
49 | - private long timestamp = System.currentTimeMillis(); | |
50 | - | |
51 | - public Result() { | |
52 | - | |
53 | - } | |
54 | - | |
55 | - public Result<T> success(String message) { | |
56 | - this.message = message; | |
57 | - this.code = CommonConstant.SC_OK_200; | |
58 | - this.success = true; | |
59 | - return this; | |
60 | - } | |
61 | - | |
62 | - | |
63 | - public static Result<Object> ok() { | |
64 | - Result<Object> r = new Result<Object>(); | |
65 | - r.setSuccess(true); | |
66 | - r.setCode(CommonConstant.SC_OK_200); | |
67 | - r.setMessage("成功"); | |
68 | - return r; | |
69 | - } | |
70 | - | |
71 | - public static Result<Object> ok(String msg) { | |
72 | - Result<Object> r = new Result<Object>(); | |
73 | - r.setSuccess(true); | |
74 | - r.setCode(CommonConstant.SC_OK_200); | |
75 | - r.setMessage(msg); | |
76 | - return r; | |
77 | - } | |
78 | - | |
79 | - public static Result<Object> ok(Object data) { | |
80 | - Result<Object> r = new Result<Object>(); | |
81 | - r.setSuccess(true); | |
82 | - r.setCode(CommonConstant.SC_OK_200); | |
83 | - r.setResult(data); | |
84 | - return r; | |
85 | - } | |
86 | - | |
87 | - public static Result<Object> error(String msg) { | |
88 | - return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg); | |
89 | - } | |
90 | - | |
91 | - public static Result<Object> error(int code, String msg) { | |
92 | - Result<Object> r = new Result<Object>(); | |
93 | - r.setCode(code); | |
94 | - r.setMessage(msg); | |
95 | - r.setSuccess(false); | |
96 | - return r; | |
97 | - } | |
98 | - | |
99 | - public Result<T> error500(String message) { | |
100 | - this.message = message; | |
101 | - this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500; | |
102 | - this.success = false; | |
103 | - return this; | |
104 | - } | |
105 | - /** | |
106 | - * 无权限访问返回结果 | |
107 | - */ | |
108 | - public static Result<Object> noauth(String msg) { | |
109 | - return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg); | |
110 | - } | |
1 | +package org.jeecg.common.api.vo; | |
2 | + | |
3 | +import java.io.Serializable; | |
4 | +import io.swagger.annotations.ApiModel; | |
5 | +import io.swagger.annotations.ApiModelProperty; | |
6 | +import org.jeecg.common.constant.CommonConstant; | |
7 | +import lombok.Data; | |
8 | + | |
9 | +/** | |
10 | + * 接口返回数据格式 | |
11 | + * @author scott | |
12 | + * @email jeecgos@163.com | |
13 | + * @date 2019年1月19日 | |
14 | + */ | |
15 | +@Data | |
16 | +@ApiModel(value="接口返回对象", description="接口返回对象") | |
17 | +public class Result<T> implements Serializable { | |
18 | + | |
19 | + private static final long serialVersionUID = 1L; | |
20 | + | |
21 | + /** | |
22 | + * 成功标志 | |
23 | + */ | |
24 | + @ApiModelProperty(value = "成功标志") | |
25 | + private boolean success = true; | |
26 | + | |
27 | + /** | |
28 | + * 返回处理消息 | |
29 | + */ | |
30 | + @ApiModelProperty(value = "返回处理消息") | |
31 | + private String message = "操作成功!"; | |
32 | + | |
33 | + /** | |
34 | + * 返回代码 | |
35 | + */ | |
36 | + @ApiModelProperty(value = "返回代码") | |
37 | + private Integer code = 0; | |
38 | + | |
39 | + /** | |
40 | + * 返回数据对象 data | |
41 | + */ | |
42 | + @ApiModelProperty(value = "返回数据对象") | |
43 | + private T result; | |
44 | + | |
45 | + /** | |
46 | + * 时间戳 | |
47 | + */ | |
48 | + @ApiModelProperty(value = "时间戳") | |
49 | + private long timestamp = System.currentTimeMillis(); | |
50 | + | |
51 | + public Result() { | |
52 | + | |
53 | + } | |
54 | + | |
55 | + public Result<T> success(String message) { | |
56 | + this.message = message; | |
57 | + this.code = CommonConstant.SC_OK_200; | |
58 | + this.success = true; | |
59 | + return this; | |
60 | + } | |
61 | + | |
62 | + @Deprecated | |
63 | + public static Result<Object> ok() { | |
64 | + Result<Object> r = new Result<Object>(); | |
65 | + r.setSuccess(true); | |
66 | + r.setCode(CommonConstant.SC_OK_200); | |
67 | + r.setMessage("成功"); | |
68 | + return r; | |
69 | + } | |
70 | + | |
71 | + @Deprecated | |
72 | + public static Result<Object> ok(String msg) { | |
73 | + Result<Object> r = new Result<Object>(); | |
74 | + r.setSuccess(true); | |
75 | + r.setCode(CommonConstant.SC_OK_200); | |
76 | + r.setMessage(msg); | |
77 | + return r; | |
78 | + } | |
79 | + | |
80 | + @Deprecated | |
81 | + public static Result<Object> ok(Object data) { | |
82 | + Result<Object> r = new Result<Object>(); | |
83 | + r.setSuccess(true); | |
84 | + r.setCode(CommonConstant.SC_OK_200); | |
85 | + r.setResult(data); | |
86 | + return r; | |
87 | + } | |
88 | + | |
89 | + public static<T> Result<T> OK() { | |
90 | + Result<T> r = new Result<T>(); | |
91 | + r.setSuccess(true); | |
92 | + r.setCode(CommonConstant.SC_OK_200); | |
93 | + r.setMessage("成功"); | |
94 | + return r; | |
95 | + } | |
96 | + | |
97 | + public static<T> Result<T> OK(T data) { | |
98 | + Result<T> r = new Result<T>(); | |
99 | + r.setSuccess(true); | |
100 | + r.setCode(CommonConstant.SC_OK_200); | |
101 | + r.setResult(data); | |
102 | + return r; | |
103 | + } | |
104 | + | |
105 | + public static<T> Result<T> OK(String msg, T data) { | |
106 | + Result<T> r = new Result<T>(); | |
107 | + r.setSuccess(true); | |
108 | + r.setCode(CommonConstant.SC_OK_200); | |
109 | + r.setMessage(msg); | |
110 | + r.setResult(data); | |
111 | + return r; | |
112 | + } | |
113 | + | |
114 | + public static Result<Object> error(String msg) { | |
115 | + return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg); | |
116 | + } | |
117 | + | |
118 | + public static Result<Object> error(int code, String msg) { | |
119 | + Result<Object> r = new Result<Object>(); | |
120 | + r.setCode(code); | |
121 | + r.setMessage(msg); | |
122 | + r.setSuccess(false); | |
123 | + return r; | |
124 | + } | |
125 | + | |
126 | + public Result<T> error500(String message) { | |
127 | + this.message = message; | |
128 | + this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500; | |
129 | + this.success = false; | |
130 | + return this; | |
131 | + } | |
132 | + /** | |
133 | + * 无权限访问返回结果 | |
134 | + */ | |
135 | + public static Result<Object> noauth(String msg) { | |
136 | + return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg); | |
137 | + } | |
111 | 138 | } |
112 | 139 | \ No newline at end of file |
... | ... |