java系统内部 返回结果封装类

2021/8/19 9:36:11

本文主要是介绍java系统内部 返回结果封装类,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

public class BaseResponse implements Serializable {
    public static int RESP_CODE_OK = 200;
    protected boolean success;
    protected int code;
    protected String msg;
    protected String redirectUrl;

    public BaseResponse() {
    }

    public BaseResponse(boolean success, int code, String msg) {
        this.success = success;
        this.code = code;
        this.msg = msg;
    }

    public BaseResponse(boolean success, int code, String msg, String redirectUrl) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.msg = redirectUrl;
    }

    public boolean isSuccess() {
        return this.success;
    }

    public int getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public String getRedirectUrl() {
        return this.redirectUrl;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

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

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

    public void setRedirectUrl(String redirectUrl) {
        this.redirectUrl = redirectUrl;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof BaseResponse)) {
            return false;
        } else {
            BaseResponse other = (BaseResponse)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.isSuccess() != other.isSuccess()) {
                return false;
            } else if (this.getCode() != other.getCode()) {
                return false;
            } else {
                label40: {
                    Object this$msg = this.getMsg();
                    Object other$msg = other.getMsg();
                    if (this$msg == null) {
                        if (other$msg == null) {
                            break label40;
                        }
                    } else if (this$msg.equals(other$msg)) {
                        break label40;
                    }

                    return false;
                }

                Object this$redirectUrl = this.getRedirectUrl();
                Object other$redirectUrl = other.getRedirectUrl();
                if (this$redirectUrl == null) {
                    if (other$redirectUrl != null) {
                        return false;
                    }
                } else if (!this$redirectUrl.equals(other$redirectUrl)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof BaseResponse;
    }

    public int hashCode() {
        int result = 1;
        result = result * 59 + (this.isSuccess() ? 79 : 97);
        result = result * 59 + this.getCode();
        Object $msg = this.getMsg();
        result = result * 59 + ($msg == null ? 43 : $msg.hashCode());
        Object $redirectUrl = this.getRedirectUrl();
        result = result * 59 + ($redirectUrl == null ? 43 : $redirectUrl.hashCode());
        return result;
    }

    public String toString() {
        return "BaseResponse(success=" + this.isSuccess() + ", code=" + this.getCode() + ", msg=" + this.getMsg() + ", redirectUrl=" + this.getRedirectUrl() + ")";
    }
}
public class Response<T> extends BaseResponse {
    private T data;

    public Response(Boolean success, int code, String msg) {
        super(success, code, msg);
        this.data = null;
    }

    public Response(Boolean success, T result, int code, String msg) {
        super(success, code, msg);
        this.data = result;
    }

    public Response() {
    }

    public static <T> Response<T> ok() {
        return new Response(true, RESP_CODE_OK, (String) null);
    }

    public static <T> Response<T> ok(T result) {
        return new Response(true, result, RESP_CODE_OK, (String) null);
    }

    public static <T> Response<T> fail(int code, String respMsg) {
        return new Response(false, code, respMsg);
    }

    public static <T> Response<T> fail(int code, String msg, Throwable e) {
        return new Response(false, code, msg);
    }

    public static <T> Response<T> fail(int code, String msgFormat, Object... args) {
        return new Response(false, code, String.format(msgFormat, args));
    }

    public static <T> Response<T> fail(String msg) {
        return fail(-1, msg);
    }

    public boolean isOk() {
        return this.success;
    }

    public T getData() {
        return this.data;
    }

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

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Response)) {
            return false;
        } else {
            Response<?> other = (Response) o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof Response;
    }

    public int hashCode() {
        int result = 1;
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        return result;
    }

    public String toString() {
        return "Response(data=" + this.getData() + ")";
    }
}


这篇关于java系统内部 返回结果封装类的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程