接口返回统一格式

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_33417035/article/details/79568116
//get set方法未加,正常项目中需添加
public class Result<T> {
    private T result;
    private boolean success = true;
    private int errorCode;
    private String errorMessage;
    private Throwable reason;

    public Result(T result) {
        if(result == null)
        {
            this.success = false;
            this.errorCode = -1;
        }
        this.result = result;
    }

    public Result(int code,String errorMessage,T result,Throwable reason) {
        if(result == null)
        {
            this.errorCode = -1;
        }
        else
        {
            this.errorCode = code;
        }
        this.success = false;
        this.result = result;
        this.errorMessage = errorMessage;
        this.reason = reason;
    }

    public Result(int errorCode, String errorMessage) {
        this(errorCode,errorMessage,null);
    }

    public Result(int errorCode, String errorMessage, Throwable reason) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
        this.reason = reason;
        this.success=false;
    }

}
展开阅读全文

没有更多推荐了,返回首页