chen.lin
昨天 b003a49794f49a329e2702918ecfc8d14b371d0d
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
package com.vincent.rsf.openApi.entity.dto;
 
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 r = new CommonResponse();
        r.setCode(200);
        r.setMsg("操作成功");
        return r;
    }
 
    /** 8.2.3 格式:成功且 data 仅含 result */
    public static CommonResponse okWithResult() {
        return ok().setData(ResultData.success());
    }
 
    public static CommonResponse error(String msg) {
        CommonResponse r = new CommonResponse();
        r.setCode(500);
        r.setMsg(msg != null ? msg : "操作失败");
        r.setData(ResultData.fail());
        return r;
    }
 
}