ResultVo.java 1.19 KB
package com.viontech.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: zhuhai
 * Date: 2023-04-04
 * Time: 16:08
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultVo<T> {

    private String code;

    private String message;

    private T data;


    public static ResultVo<Void> success() {
        return success("success", null);
    }


    public static <T> ResultVo<T> success(T data) {
        return success("success", data);
    }

    public static <T> ResultVo<T> success(String message, T data) {
        ResultVo<T> resultVo = new ResultVo<>();
        resultVo.setCode("200");
        resultVo.setMessage(message);
        resultVo.setData(data);
        return resultVo;
    }

    public static ResultVo<Void> error() {
        return error("System error!");
    }

    public static ResultVo<Void> error(String code, String message) {
        ResultVo<Void> resultVo = new ResultVo<>();
        resultVo.setCode(code);
        resultVo.setMessage(message);
        return resultVo;
    }

    public static  ResultVo<Void> error(String message) {
        return error("500", message);
    }


}