Message.java 1.44 KB
package com.viontech.storage.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * .
 *
 * @author 谢明辉
 * @date 2021/11/8
 */

@Getter
@Setter
@Accessors(chain = true)
public class Message<T> {

    private String msg;
    private boolean success;
    private Integer code;
    private T data;


    public static <T> Message<T> success(String msg, T data) {
        return new Message<T>().setMsg(msg).setCode(200).setSuccess(true).setData(data);
    }

    public static <T> Message<T> success(T data) {
        return new Message<T>().setMsg("成功").setCode(200).setSuccess(true).setData(data);
    }

    public static <T> Message<T> success() {
        return new Message<T>().setMsg("成功").setCode(200).setSuccess(true).setData(null);
    }

    public static <T> Message<T> success(String msg) {
        return new Message<T>().setMsg(msg).setCode(200).setData(null);
    }


    public static <T> Message<T> error(String msg, T data) {
        return new Message<T>().setMsg(msg).setCode(500).setData(data);
    }

    public static <T> Message<T> error(String msg) {
        return new Message<T>().setMsg(msg).setCode(500).setData(null);
    }

    public static <T> Message<T> error(T data) {
        return new Message<T>().setMsg("失败").setCode(500).setData(data);
    }

    public static <T> Message<T> error() {
        return new Message<T>().setMsg("失败").setCode(500).setData(null);
    }


}