1 package com.-.it.regioc.bean.result;
2
3 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 import lombok.Getter;
5 import org.apache.http.HttpStatus;
6 import java.io.Serializable;
7
8 /**
9 * 响应结果
10 *
11 * @since 2019年10月25日
12 */
13 @Getter
14 @JsonIgnoreProperties(value = "class")
15 public class ResultVO<T> implements Serializable {
16
17 private static final long serialVersionUID = -4844291434132745432L;
18
19 /**
20 * 状态码
21 */
22 protected String code;
23
24 /**
25 * 状态信息
26 */
27 protected String message;
28
29 /**
30 * 结果
31 */
32 protected T data;
33
34 public ResultVO(String code) {
35 super();
36 this.code = code;
37 }
38
39 public ResultVO(String code, String message) {
40 super();
41 this.code = code;
42 this.message = message;
43 }
44
45 /**
46 * 成功的时候调用
47 *
48 * @return 当前对象
49 */
50 public static ResultVO successful() {
51 return new ResultVO<>(String.valueOf(HttpStatus.SC_OK), "SUCCESS");
52 }
53
54 /**
55 * 失败的时候调用
56 *
57 * @return 当前对象
58 */
59 public static ResultVO fail() {
60 return new ResultVO<>(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR), "FAILED");
61 }
62
63 /**
64 * 返回结果自定义message的时候调用
65 *
66 * @param code 状态码
67 * @return 当前对象
68 */
69 public ResultVO code(String code) {
70 this.code = code;
71 return this;
72 }
73
74 /**
75 * 返回结果自定义message的时候调用
76 *
77 * @param message 状态信息
78 * @return 当前对象
79 */
80 public ResultVO message(String message) {
81 this.message = message;
82 return this;
83 }
84
85 /**
86 * 返回结果的时候调用
87 *
88 * @param data 状态信息
89 * @return 当前对象
90 */
91 public ResultVO data(T data) {
92 this.data = data;
93 return this;
94 }
95
96 /**
97 * 设置状态码和信息
98 *
99 * @param code 状态码
100 * @param message 状态信息
101 * @return 当前对象
102 */
103 public ResultVO<T> setCodeAndMessage(String code, String message) {
104 this.code = code;
105 this.message = message;
106 return this;
107 }
108 }