添加了Swagger的注解
/**
* 接口返回数据格式
*
* @param <T>
* @author 60974
*/
@Data
@ApiModel(value = "接口返回对象", description = "接口返回对象")
public class Result<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 成功标志
*/
@ApiModelProperty(value = "成功标志")
private boolean success = true;
/**
* 返回处理消息
*/
@ApiModelProperty(value = "返回处理消息")
private String message = "操作成功!";
/**
* 返回代码
*/
@ApiModelProperty(value = "返回代码")
private Integer code = 200;
/**
* 返回数据对象 data
*/
@ApiModelProperty(value = "返回数据对象")
private T result;
/**
* 时间戳
*/
@ApiModelProperty(value = "时间戳")
private long timestamp = System.currentTimeMillis();
public Result() {
}
public Result<T> error500(String message) {
this.message = message;
this.code = CommonConstant.ERROR_500;
this.success = false;
return this;
}
public Result<T> success() {
this.message = "成功";
this.code = CommonConstant.OK_200;
this.success = true;
return this;
}
public Result<T> success(String message) {
this.message = message;
this.code = CommonConstant.OK_200;
this.success = true;
return this;
}
public static Result<Object> ok() {
Result<Object> r = new Result<Object>();
r.setSuccess(true);
r.setCode(CommonConstant.OK_200);
r.setMessage("成功");
return r;
}
public static Result<Object> ok(String msg) {
Result<Object> r = new Result<Object>();
r.setSuccess(true);
r.setCode(CommonConstant.OK_200);
r.setMessage(msg);
return r;
}
public static Result<Object> ok(Object data) {
Result<Object> r = new Result<Object>();
r.setSuccess(true);
r.setCode(CommonConstant.OK_200);
r.setResult(data);
return r;
}
public static Result<Object> error(String msg) {
return error(CommonConstant.ERROR_500, msg);
}
public static Result<Object> error(int code, String msg) {
Result<Object> r = new Result<Object>();
r.setCode(code);
r.setMessage(msg);
r.setSuccess(false);
return r;
}
/**
* 无权限访问返回结果
*/
public static Result<Object> noauth(String msg) {
return error(CommonConstant.NO_AUTHZ, msg);
}
/**
* 未获取到用户信息
*/
public static Result<Object> nologin(String msg) {
return error(CommonConstant.NO_LOGIN, msg);
}
接口返回值状态码常量
public interface CommonConstant {
/**
* 正常状态
*/
public static final Integer STATUS_NORMAL = 0;
/**
* 禁用状态
*/
public static final Integer STATUS_DISABLE = -1;
/**
* 删除标志
*/
public static final Integer DEL_FLAG_1 = 1;
/**
* 未删除
*/
public static final Integer DEL_FLAG_0 = 0;
/**
* 系统日志类型: 登录
*/
public static final int LOG_TYPE_1 = 1;
/**
* 系统日志类型: 操作
*/
public static final int LOG_TYPE_2 = 2;
/**
* 用户的serviceSystemId SESION
*/
public static final String SESSION_SERVICE_SYSTEM = "SESSION_SERVICE_SYSTEM";
/** {@code 500 Server Error} (HTTP/1.0 - RFC 1945) */
public static final Integer ERROR_500 = 500;
/** {@code 200 OK} (HTTP/1.0 - RFC 1945) */
public static final Integer OK_200 = 200;
/** 访问权限认证未通过 510 */
public static final Integer NO_AUTHZ = 510;
/** 访问权限认证未通过 510 */
public static final Integer NO_LOGIN= 401;
/** 登录用户令牌缓存KEY前缀 */
public static final int TOKEN_EXPIRE_TIME = 3600; // 3600秒即是一小时
public static final String PREFIX_USER_TOKEN = "PREFIX_USER_TOKEN_";
/** 字典翻译文本后缀 */
public static final String DICT_TEXT_SUFFIX = "_dictText";
}