Springboot后端返回结果链式编程Result

Springboot后端返回结果链式编程Result,第1张

Springboot后端返回结果链式编程Result

Result实体类

@Data
public class Result {
    @ApiModelProperty(value = "是否成功")
    private Boolean success;
    @ApiModelProperty(value = "返回码")
    private Integer code;
    @ApiModelProperty(value = "返回消息")
    private String message;
    @ApiModelProperty(value = "返回数据")
    private Object data;

    private Result(){};

    public static Result success() {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.success);
        result.setMessage(" *** 作成功");
        return result;
    }
    public static Result error() {
        Result result = new Result();
        result.setCode(ResultCode.ERROR);
        result.setMessage(" *** 作失败");
        result.setSuccess(false);
        return result;
    }

    
    public Result success(Boolean success) {
        this.setSuccess(true);
        return this;
    }

    public Result message(String message) {
        this.setMessage(message);
        return this;
    }

    public Result code(Integer code) {
        this.setCode(code);
        return this;
    }

    public Result data(Object data) {
        this.setData(data);
        return this;
    }
}

返回码接口

public interface ResultCode {
    public static Integer success = 20000;
    public static Integer ERROR = 20001;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5661258.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存