zoukankan      html  css  js  c++  java
  • Response响应工具类

    技术交流群: 233513714

    import com.google.common.base.Objects;
    
    import java.io.Serializable;
    
    public class Response<T> implements Serializable {
        private static final long serialVersionUID = 8350327877975282483L;
        private boolean success;
        private T result;
        private String statusCode;
        private String message;
    
        public Response() {
        }
    
        public Response(T result) {
            this.success = true;
            this.result = result;
        }
    
        public Response(boolean flag, T result) {
            if (flag) {
                this.success = true;
                this.result = result;
            } else {
                this.success = false;
                this.statusCode = (String) result;
            }
        }
    
        public Response(String statusCode) {
            this.success = false;
            this.statusCode = statusCode;
        }
    
        public Response(String statusCode, String message) {
            this.statusCode = statusCode;
            this.message = message;
        }
    
        public boolean isSuccess() {
            return success;
        }
    
        public T getResult() {
            return result;
        }
    
        public void setResult(T result) {
            success = true;
            this.result = result;
        }
    
        public String getStatusCode() {
            return statusCode;
        }
    
        public void setStatusCode(String statusCode) {
            this.success = false;
            this.statusCode = statusCode;
        }
    
        public String getMessage() {
            return message;
        }
    
        public void setMessage(String message) {
            this.message = message;
        }
    
        @Override
        public boolean equals(Object obj) {
            if (this == obj) return true;
            if (obj == null || getClass() != obj.getClass()) return false;
            Response response = (Response) obj;
            if (success != response.success) return false;
            if (!statusCode.equals(response.statusCode)) return false;
            if (!result.equals(response.result)) return false;
    
            return true;
        }
    
        @Override
        public int hashCode() {
            int result1 = (success ? 1 : 0);
            result1 = 31 * result1 + result.hashCode();
            result1 = 31 * result1 + statusCode.hashCode();
            return result1;
        }
    
        @Override
        public String toString() {
            return Objects.toStringHelper(this)
                    .add("success", success)
                    .add("result", result)
                    .add("statusCode", statusCode)
                    .omitNullValues()
                    .toString();
        }
    }
  • 相关阅读:
    笔记:多线程访问ConcurrentHashMap对key加锁
    根据第三列去重
    Correct the classpath of your application so that it contains a single, compatible version of org.apache.log4j.ConsoleAppender
    python 中将源配置为阿里
    criteria两个 判断
    git flow
    sqlmap用法详解
    MongoDB 入门
    MongoDB 手册
    OWASP TOP 10简单介绍
  • 原文地址:https://www.cnblogs.com/cnndevelop/p/7123032.html
Copyright © 2011-2022 走看看