首页 > 代码库 > Response响应工具类
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(); } }
Response响应工具类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。