Message.java
1.18 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
package com.viontech.storage.entity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/8
*/
@Getter
@Setter
@Accessors(chain = true)
public class Message<T> {
private String msg;
private boolean success;
private Integer code;
private T data;
public static <T> Message<T> success(String msg, T data) {
return new Message<T>().setMsg(msg).setCode(200).setSuccess(true).setData(data);
}
public static <T> Message<T> success(T data) {
return new Message<T>().setMsg("成功").setCode(200).setSuccess(true).setData(data);
}
public static <T> Message<T> success() {
return new Message<T>().setMsg("成功").setCode(200).setSuccess(true).setData(null);
}
public static <T> Message<T> error(String msg, T data) {
return new Message<T>().setMsg(msg).setCode(500).setData(data);
}
public static <T> Message<T> error(T data) {
return new Message<T>().setMsg("失败").setCode(500).setData(data);
}
public static <T> Message<T> error() {
return new Message<T>().setMsg("失败").setCode(500).setData(null);
}
}