Java ResponseDto<T>
import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class ResponseDto<T> { @ApiModelProperty(value = "是否成功,true=成功,false=失败", position = 1) private boolean success = true; @ApiModelProperty(value = "描述", position = 2) private String msg = "操作成功"; @ApiModelProperty(value = "消息体", position = 3) private T data; public ResponseDto() { } public ResponseDto(boolean success) { this.success = success; } public ResponseDto(boolean success, String msg) { this.success = success; this.msg = msg; } public ResponseDto(boolean success, String msg, T data) { this.success = success; this.msg = msg; this.data = data; } public ResponseDto(T data) { this.data = data; } /** * 成功,并返回消息体 * @param data * @return */ public static <T>ResponseDto<T> ok(T data) { return new ResponseDto(data); } /** * 失败,返回消息内容 * @param msg * @return */ public static <T>ResponseDto<T> fail(String msg) { return new ResponseDto(false, msg); } }
有些事情,没经历过不知道原理,没失败过不明白奥妙,没痛苦过不了解真谛。临渊羡鱼,不如退而结网!

浙公网安备 33010602011771号