响应结果统一处理工具类

@Date
public class Response<T> implements Serializable{
	private static final long serialVersionUID = 1257916683118688101L;
	private Integer code;
    private String msg;	
    private T data;

	public Response() {
		this.code = ResultEnum.SUCCESS.code;
        this.msg = ResultEnum.SUCCESS.msg;
    }
	
	public Response(T data) {
        this.code = ResultEnum.SUCCESS.getCode();
        this.msg = ResultEnum.SUCCESS.getMsg();
        this.data = data;
    }
	
	public Response(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    
    public Response(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
	public static Response<RestEnum> success() {
        return new BdpServiceResponse(BdpResponseEnum.SUCCESS);
    }
    
    public static <T> Response<T> success(T data) {
        return new Response(data);
    }

	 public static <T> BdpServiceResponse<T> success(T data, int code, String msg) {
        return new Response(data, code, msg);
    }
    
    public static <T> Response<T> failure() {
        return new Response(ResultEnum.FAILURE.getCode(), ResultEnum.FAILURE.getMsg());
    }

	public static <T> Response<T> failure(int code, String msg) {
        return failure((Object)null, code, msg);
    }

	public static <T> Response<T> failure(T data, int code, String msg) {
        return new Response((Object)null, code, msg);
    }

	public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof BdpServiceResponse)) {
            return false;
        } else {
            BdpServiceResponse<?> other = (BdpServiceResponse)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getCode() != other.getCode()) {
                return false;
            } else {
                Object this$msg = this.getMsg();
                Object other$msg = other.getMsg();
                if (this$msg == null) {
                    if (other$msg != null) {
                        return false;
                    }
                } else if (!this$msg.equals(other$msg)) {
                    return false;
                }

                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 BdpServiceResponse;
    }

    public int hashCode() {
        int PRIME = true;
        int result = 1;
        int result = result * 59 + this.getCode();
        Object $msg = this.getMsg();
        result = result * 59 + ($msg == null ? 43 : $msg.hashCode());
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        return result;
    }
}
public enum ResultEnum {
    SUCCESS(0, "操作成功."),
    FAILURE(201, "操作失败."),
    PARAM_ERROR(202, "参数错误."),
    UNKNOWN_ERROR(203, "未知错误."),
    DATABASE_ERROR(204, "数据库操作异常."),
    ILLEGAL(205, "非法操作.");
	@Getter
    private int code;
    @Getter
    private String msg;

    ResultEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值