MCPcopy Create free account
hub / github.com/csx-bill/quick-boot / R

Class R

src/main/java/com/quick/boot/modules/common/vo/R.java:13–70  ·  view source on GitHub ↗

通用API响应结果封装类 @param 响应数据类型

Source from the content-addressed store, hash-verified

11 * @param <T> 响应数据类型
12 */
13@ToString // 自动生成toString方法
14@NoArgsConstructor // 自动生成无参构造器
15@AllArgsConstructor // 自动生成全参构造器
16@Accessors(chain = true) // 支持链式调用
17@FieldNameConstants // 生成字段名称常量
18public class R<T> implements Serializable {
19 private static final long serialVersionUID = 1L;
20
21 @Getter
22 @Setter
23 private int status;
24
25 @Getter
26 @Setter
27 private String msg;
28
29 @Getter
30 @Setter
31 private T data;
32
33 public static <T> R<T> ok() {
34 return restResult(null, CommonConstants.SUCCESS, null);
35 }
36
37 public static <T> R<T> ok(T data) {
38 return restResult(data, CommonConstants.SUCCESS, null);
39 }
40
41 public static <T> R<T> ok(T data, String msg) {
42 return restResult(data, CommonConstants.SUCCESS, msg);
43 }
44
45 public static <T> R<T> failed() {
46 return restResult(null, CommonConstants.FAIL, null);
47 }
48
49 public static <T> R<T> failed(String msg) {
50 return restResult(null, CommonConstants.FAIL, msg);
51 }
52
53 public static <T> R<T> failed(T data) {
54 return restResult(data, CommonConstants.FAIL, null);
55 }
56 public static <T> R<T> failed(int code, String msg) {
57 return restResult(null, code, msg);
58 }
59 public static <T> R<T> failed(T data, String msg) {
60 return restResult(data, CommonConstants.FAIL, msg);
61 }
62
63 public static <T> R<T> restResult(T data, int status, String msg) {
64 R<T> apiResult = new R<>();
65 apiResult.setStatus(status);
66 apiResult.setData(data);
67 apiResult.setMsg(msg);
68 return apiResult;
69 }
70}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected