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
package com.vincent.rsf.openApi.entity.dto;
 
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
 
/**
 * @author Ryan
 * @date 2025/8/27
 * @description: 通用响应结果
 * @version 1.0
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "CommonResponse", description = "通用响应结果 ")
public class CommonResponse {
 
    @ApiModelProperty("响应编码")
    private Integer code;
 
    @ApiModelProperty("响应消息")
    private String msg;
 
    @ApiModelProperty("响应结果")
    private Object data;
 
    /**
     * 成功响应
     */
    public static CommonResponse ok() {
        CommonResponse response = new CommonResponse();
        response.setCode(200);
        response.setMsg("操作成功");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", "SUCCESS");
        response.setData(jsonObject);
        return response;
    }
 
    public static CommonResponse ok(Object data) {
        CommonResponse response = new CommonResponse();
        response.setCode(200);
        response.setMsg("操作成功");
        response.setData(data);
        return response;
    }
 
    /**
     * 失败响应
     */
    public static CommonResponse error(String msg) {
        CommonResponse response = new CommonResponse();
        response.setCode(500);
        response.setMsg(msg);
        return response;
    }
 
}