springBoot lombok返回数据外层实体

/**
 * @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);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值