All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.bootystar.helper.databind.Result Maven / Gradle / Ivy

The newest version!
package io.github.bootystar.helper.databind;


import lombok.Data;

/**
 * 通用数据返回类型
 * @author booty
 */
@Data
public class Result {
    public static final Integer UNAUTHORIZED = -1;
    public static final Integer SUCCESS = 1;
    public static final Integer FAILURE = 2;
    public static final Integer ERROR = 3;

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

    public static  Result success(String msg, T data) {
        Result result = new Result<>();
        result.setCode(SUCCESS);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static  Result success(T data) {
        Result result = new Result<>();
        result.setCode(SUCCESS);
        result.setData(data);
        return result;
    }

    public static  Result success() {
        Result result = new Result<>();
        result.setCode(SUCCESS);
        return result;
    }

    public static  Result failure(String msg) {
        Result result = new Result<>();
        result.setCode(FAILURE);
        result.setMsg(msg);
        return result;
    }

    public static  Result failure(String msg, T data) {
        Result result = new Result<>();
        result.setCode(FAILURE);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static  Result error(String msg) {
        Result result = new Result<>();
        result.setCode(ERROR);
        result.setMsg(msg);
        return result;
    }

    public static  Result error(String msg, T data) {
        Result result = new Result<>();
        result.setCode(ERROR);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static  Result unauthorized(String msg, T data) {
        Result result = new Result<>();
        result.setCode(UNAUTHORIZED);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static  Result unauthorized() {
        Result result = new Result<>();
        result.setCode(UNAUTHORIZED);
        result.setMsg("权限不足");
        return result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy