|
@@ -0,0 +1,59 @@
|
|
1
|
+package com.unissoft.webservice.model;
|
|
2
|
+
|
|
3
|
+import lombok.Data;
|
|
4
|
+
|
|
5
|
+import java.io.Serializable;
|
|
6
|
+
|
|
7
|
+// 返回基类
|
|
8
|
+@Data
|
|
9
|
+public class ResponseEntity<T> implements Serializable {
|
|
10
|
+
|
|
11
|
+ private static final long serialVersionUID = -2825436079063723409L;
|
|
12
|
+
|
|
13
|
+ //成功
|
|
14
|
+ private static final String OK = "200";
|
|
15
|
+ //失败
|
|
16
|
+ private static final String FAILED = "600";
|
|
17
|
+ private static final String BUSSINESS_FAILED = "550";
|
|
18
|
+ private static final String UNAUTHENTICATION = "401";
|
|
19
|
+
|
|
20
|
+ private String retCode;
|
|
21
|
+ private String message;
|
|
22
|
+ private T data;
|
|
23
|
+
|
|
24
|
+ private static <T> ResponseEntity<T> buildResponse(String retCode, String message, T data) {
|
|
25
|
+ ResponseEntity<T> responseEntity = new ResponseEntity<T>();
|
|
26
|
+ responseEntity.retCode = retCode;
|
|
27
|
+ responseEntity.message = message;
|
|
28
|
+ responseEntity.data = data;
|
|
29
|
+ return responseEntity;
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ public static <T> ResponseEntity<T> ok() {
|
|
33
|
+ return buildResponse(ResponseEntity.OK, "success", null);
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ public static <T> ResponseEntity<T> ok(T data) {
|
|
37
|
+ return buildResponse(ResponseEntity.OK, "success", data);
|
|
38
|
+
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ public static <T> ResponseEntity<T> ok(String message, T data) {
|
|
42
|
+ return buildResponse(ResponseEntity.OK, message, data);
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+ public static <T> ResponseEntity<T> failed(String message) {
|
|
47
|
+ return buildResponse(ResponseEntity.FAILED, message, null);
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ public static <T> ResponseEntity<T> businessFailed(String message) {
|
|
51
|
+ return buildResponse(ResponseEntity.BUSSINESS_FAILED, message, null);
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ public static <T> ResponseEntity<T> unauthentication(String message) {
|
|
55
|
+ return buildResponse(ResponseEntity.UNAUTHENTICATION, message, null);
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+}
|
|
59
|
+
|