package com.rj.common;


/**
 * 返回值的标准格式
 */
public class Result<T> {
    /**
     * 状态码
     */
    private int code=200;

    /**
     * 消息提示
     */
    private String msg="OK";
    /**
     * 返回数据
     */
    private Object data;

    /**
     * 成功 不返回数据
     */
    public static <T> Result<T> ok(){
        return new Result<T>();
    }

    /**
     * 失败返回自定义消息
     */
    public static <T> Result<T> error(String msg){
        return new Result<T>(-1,msg);
    }

    /**
     * 失败返回系统异常消息
     */
    public static <T> Result<T> error(){
        return new Result<T>(-1,"系统异常");
    }

    /**
     * 成功返回数据
     */
    public static <T> Result<T> ok(Object data){
        return new Result<T>(data);
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result() {
    }

    public Result(Object data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
