Result
1 package com.-.it.regioc.bean.result;
2
3 import lombok.Data;
4 import org.apache.http.HttpStatus;
5 import java.io.Serializable;
6
7 /**
8 * 响应结果
9 */
10 @Data
11 public class Result<T> implements Serializable {
12
13 private static final long serialVersionUID = -4844291434132745432L;
14
15 /**
16 * 状态码
17 */
18 protected String code;
19
20 /**
21 * 状态信息
22 */
23 protected String message;
24
25 /**
26 * 结果
27 */
28 protected T data;
29
30 public Result(String code, String message, T data) {
31 this.code = code;
32 this.message = message;
33 this.data = data;
34 }
35
36 /**
37 * 成功的时候调用
38 */
39 public static <T> Result<T> success(T data) {
40 return new Result<>(String.valueOf(HttpStatus.SC_OK), "SUCCESS", data);
41 }
42
43 /**
44 * 成功无参
45 */
46 public static <T> Result<T> success() {
47 return new Result<>(String.valueOf(HttpStatus.SC_OK), "SUCCESS", null);
48 }
49
50 /**
51 * 失败的时候调用
52 */
53 public static <T> Result<T> fail() {
54 return new Result<>(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR), "FAILED", null);
55 }
56
57 /**
58 * 失败的时候调用
59 */
60 public static <T> Result<T> fail(String message) {
61 return new Result<>(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR), message, null);
62 }
63
64 /**
65 * 判断响应是否成功
66 */
67 public boolean isSuccess() {
68 return String.valueOf(HttpStatus.SC_OK).equals(this.code);
69 }
70
71 }