#
vincentlu
2025-02-13 e6df4123693fca526040115475701bcd3e373904
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.vincent.rsf.common.domain;
 
import java.io.Serializable;
 
/**
 * 通用返回类
 * Created by vincent on 2023/3/27
 */
public class BaseResult<T> implements Serializable {
 
    private static final long serialVersionUID = -6551234415624980301L;
 
    public static final int RESULT_OK_CODE = 0;
 
    public static final int RESULT_ERROR_CODE = 1;
 
    public static final String RESULT_OK_MSG = "操作成功";
 
    public static final String RESULT_ERROR_MSG = "服务器错误";
 
    private Integer code;
 
    private String msg;
 
    private T data;
 
    public BaseResult() {
    }
 
    public BaseResult(Integer code) {
        this(code, null);
    }
 
    public BaseResult(Integer code, String msg) {
        this(code, msg, null);
    }
 
    public BaseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
 
    public Integer getCode() {
        return code;
    }
 
    public BaseResult<T> setCode(Integer code) {
        this.code = code;
        return this;
    }
 
    public String getMsg() {
        return msg;
    }
 
    public BaseResult<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }
 
    public T getData() {
        return data;
    }
 
    public BaseResult<T> setData(T data) {
        this.data = data;
        return this;
    }
 
    public BaseResult<T> add(T data) {
        this.data = data;
        return this;
    }
 
    public static BaseResult<?> ok() {
        return new BaseResult<>(RESULT_OK_CODE, RESULT_OK_MSG);
    }
 
    public static BaseResult<?> ok(String msg) {
        return ok().setMsg(msg);
    }
 
    public static BaseResult<?> error() {
        return new BaseResult<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG);
    }
 
    public static BaseResult<?> error(String msg) {
        return BaseResult.error().setMsg(msg);
    }
 
    public static BaseResult<?> define(Integer code, String msg) {
        return new BaseResult<>(code, msg);
    }
 
    public Boolean success() {
        return this.getCode().equals(RESULT_OK_CODE);
    }
 
    public Boolean fail() {
        return !success();
    }
 
}