赞
踩
问题:
/** * 返回实体 * * @author Odinpeng * @since 2023/12/5 */ import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Builder; import lombok.Data; import lombok.Getter; @Data public class ResponseBody<T> { /** * 输出信息 */ private String msg; /** * 返回数据 */ @Builder.Default @JsonInclude(JsonInclude.Include.NON_NULL) private T body = null; /** * 状态码 */ private int code; /** * 默认构造成功信息 */ public ResponseBody() { this.code = ReturnStatus.SUCCESS.getVal(); this.msg = ReturnStatus.SUCCESS.getMsg(); } public ResponseBody(int code, String msg) { this.code = code; this.msg = msg; } public ResponseBody(int code, String msg, T body) { this.code = code; this.msg = msg; this.body = body; } public static <T> ResponseBody<T> success() { return new ResponseBody<>(); } public static <T> ResponseBody<T> success(String msg) { return new ResponseBody<>(ReturnStatus.SUCCESS.getVal(), msg); } public static <T> ResponseBody<T> error(int code, String msg) { return new ResponseBody<>(code, msg); } public static <T> ResponseBody<T> error(String msg) { return new ResponseBody<>(ReturnStatus.ERROR.getVal(), msg); } public ResponseBody<T> code(int code) { this.code = code; return this; } public ResponseBody<T> msg(String msg) { this.msg = msg; return this; } public ResponseBody<T> body(T body) { this.body = body; return this; } } @Getter enum ReturnStatus { /** * 操作成功 */ SUCCESS(200, "操作成功"), /** * 系统内部错误 */ ERROR(500, "系统内部错误"); /** * 状态 */ private final int val; /** * 信息输出 */ private final String msg; /** * 有参构造 * * @param val 状态码 * @param msg 消息体 */ ReturnStatus(int val, String msg) { this.val = val; this.msg = msg; } }
/** * test fegin * * @author Odinpeng * @since 2023/12/5 **/ @FeignClient(url = "url", path = "path", name = "name") public interface TestFeign{ /** * 保存 */ @PostMapping("save") ResponseBody<?> save(@RequestBody Body body); /** * 修改 */ @PostMapping("update") ResponseBody<?> update(@RequestBody Body body); /** * 删除 */ @PostMapping("delete") ResponseBody<?> delete(@RequestBody Integer index); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。