/** * @Author 周贞荣 * @Modify 周贞荣 * @Date 2022/1/13 10:28 * @Description 服务返回外层实体 */ package webblog.vo; import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; @Getter @JsonInclude(JsonInclude.Include.NON_NULL) public class ResultVo<T> { @ApiModelProperty("状态码 500失败 200成功 2未登录 3没有权限") private int code; @ApiModelProperty("返回信息") private String msg; @ApiModelProperty("返回数据") private T data; public ResultVo() { this.code = 200; this.msg = ""; this.data = null; } public ResultVo(T data) { this.code = 200; this.msg = ""; this.data = data; } public ResultVo(T data, String msg) { this.code = 200; this.msg = msg; this.data = data; } public ResultVo(T data, String msg, int code) { this.code = code; this.msg = msg; this.data = data; } /** * 成功不需返回参数 */ public static ResultVo setSuc() { return new ResultVo(); } /** * 成功修改data */ public static <T> ResultVo setSuc(T data) { return new ResultVo(data); } /** * 成功修改data与msg */ public static <T> ResultVo setSuc(T data, String msg) { return new ResultVo(data,msg); } /** * 失败仅修改msg */ public static ResultVo setFail() { return new ResultVo(null, "服务失败", 500); } /** * 失败仅修改msg */ public static ResultVo setFail(String msg) { return new ResultVo(null, msg, 500); } /** * 失败仅修改msg与code */ public static ResultVo setFail(String msg, int code) { return new ResultVo(null, msg, code); } /** * 失败仅修改data、msg与code */ public static <T> ResultVo setFail(String msg, int code, T data) { return new ResultVo(data, msg, code); } /** * 失败仅修改msg与data */ public static <T> ResultVo setFailMsgData(String msg, T data) { return new ResultVo(data, msg, 500); } }
springBoot lombok返回数据外层实体
最新推荐文章于 2023-07-30 20:15:31 发布