1
hao
2025-05-20 8e24c6fea30d9b179375ee2893710cdec2443b13
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.app.base.data;
 
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiModelProperty;
 
import java.io.IOException;
import java.io.StringWriter;
 
/**
 * restAPI服务返回结果集
 */
public class ApiResponseResult {
 
    //返回结果,成功为true,失败为false
    @ApiModelProperty(name = "result", value ="返回结果,成功为true,失败为false")
    protected boolean result;
 
    //返回信息
    @ApiModelProperty(name = "msg", value ="返回信息")
    protected String msg = "";
 
    //返回数据
    @ApiModelProperty(name = "data", value ="返回数据")
    protected Object data;
 
    //它自定义的状态码
    @ApiModelProperty(name = "status", value ="它自定义的状态码")
    protected String status;
 
    //返回数据数量
    @ApiModelProperty(name = "count", value ="返回数据数量")
    private int count;
 
    public static ApiResponseResult success() {
        return new ApiResponseResult(true);
    }
 
    public static ApiResponseResult failure() {
        return new ApiResponseResult(false);
    }
 
    public static ApiResponseResult success(String message) {
        return new ApiResponseResult(true, message);
    }
 
    public static ApiResponseResult failure(String message) {
        return new ApiResponseResult(false, message);
    }
 
    public ApiResponseResult(){
        super();
    }
 
    public ApiResponseResult(boolean success) {
        this(success, success ? "0" : "1");
    }
 
    public ApiResponseResult(boolean success, String message) {
        this(success, message, null);
    }
 
    public ApiResponseResult(boolean success, String message, Object data) {
        this.result = success;
        this.msg = message;
        this.data = data;
        this.status = success ? "0" : "1";
    }
 
    public ApiResponseResult(String status, String message, Object data) {
        this.msg = message;
        this.data = data;
        this.status = status;
    }
 
    public ApiResponseResult(String status, String message) {
        this.msg = message;
        this.status = status;
    }
 
    public String toJsonStr() {
        ObjectMapper objMapper = new ObjectMapper();
        StringWriter str = new StringWriter();
        try {
            objMapper.writeValue(str, this);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str.toString();
    }
 
    public ApiResponseResult result(boolean result) {
        this.result = result;
        return this;
    }
 
    public ApiResponseResult message(String message) {
        this.msg = message;
        return this;
    }
 
    public ApiResponseResult data(Object data) {
        this.data = data;
        return this;
    }
 
    public ApiResponseResult status(String status) {
        this.status = status;
        return this;
    }
 
    public ApiResponseResult count(int count) {
        this.count = count;
        return this;
    }
 
    public boolean isResult() {
        return result;
    }
 
    public void setResult(boolean result) {
        this.result = result;
    }
 
    public String getMsg() {
        return msg;
    }
 
    public void setMsg(String msg) {
        this.msg = msg;
    }
 
    public void setMessage(String message){
        this.msg = message;
    }
 
    public Object getData() {
        return data;
    }
 
    public void setData(Object data) {
        this.data = data;
    }
 
    public String getStatus() {
        return status;
    }
 
    public void setStatus(String status) {
        this.status = status;
    }
 
    public int getCount() {
        return count;
    }
 
    public void setCount(int count) {
        this.count = count;
    }
}