Result返回前端實體類



import lombok.Data;

import java.util.HashMap;

/**
 * @author Administrator
 */
@Data
public class Result<T> {

    private static final long serialVersionUID = -8713837118340960775L;

    /** 成功*/
    private static final Integer SUCCESS = 0;
    /** 警告*/
    private static final Integer WARN = 1;
    /** 異常 失敗*/
    private static final Integer FAIL = 500;

    private Integer code;

    private String msg;

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

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

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

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    /**
     * 失敗並返回數據
     * @param data
     * @return
     */
    public static Result error(Object data) {
        return new Result(FAIL, data);
    }

    /**
     * 警告並返回數據
     * @param data
     * @return
     */
    public static Result warn(Object data) {
        return new Result(WARN, data);
    }

    /**
     * 成功並返回數據
     * @param msg
     * @param data
     * @return
     */
    public static Result ok(String msg, Object data) {
        return new Result(SUCCESS, msg, data);
    }

    /**
     * 帶數據
     * @param data
     * @return
     */
    public static Result ok(Object data) {
        return new Result(SUCCESS,data);
    }

    /**
     * 成功返回通用數據
     * @return
     */
    public static Result ok() {
        return new Result(SUCCESS, "操作成功");
    }

    public static Result error() {
        return Result.error("");
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM