/* * ************************************************* * Copyright (c) 2018 QMTH. All Rights Reserved. * Created by Deason on 2018-07-16 15:00:21. * ************************************************* */ package cn.com.qmth.examcloud.app.model; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import java.io.Serializable; public class Result implements Serializable { private static final long serialVersionUID = 1L; private String code;//状态码 private String desc;//描述信息 private T data;//数据 public static String DESC_200 = "请求成功!"; public static String DESC_500 = "请求失败!"; public static String DESC_403 = "无效认证信息,请先登录!"; public static String DESC_404 = "请求地址或参数错误!"; public Result() { } public Result(String code, String desc, T data) { this.code = code; this.desc = desc; this.data = data; } /** * 成功结果 */ public Result success(T data) { this.code = Constants.CODE_200; this.desc = DESC_200; this.data = data; return this; } public Result success() { this.code = Constants.CODE_200; this.desc = DESC_200; return this; } /** * 错误结果 */ public Result error(String desc) { this.code = Constants.CODE_500; this.desc = desc; return this; } public Result error() { this.code = Constants.CODE_500; this.desc = DESC_500; return this; } public Result noAuthError() { this.code = Constants.CODE_403; this.desc = DESC_403; return this; } public Result noFoundError() { this.code = Constants.CODE_404; this.desc = DESC_404; return this; } public boolean isSuccess() { if (Constants.CODE_200.equals(getCode())) { return true; } return false; } public String getCode() { return code; } public String getDesc() { return desc; } public T getData() { return data; } public void setCode(String code) { this.code = code; } public void setDesc(String desc) { this.desc = desc; } public void setData(T data) { this.data = data; } @Override public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); } }