com.sinszm.common.Response Maven / Gradle / Ivy
package com.sinszm.common;
import com.sinszm.common.exception.ApiError;
import com.sinszm.common.exception.SystemApiError;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.nutz.json.Json;
/**
* 统一返回值对象
*
* @author chenjianbo
*/
@ApiModel(value = "请求结果", description = "请求结果")
public class Response {
private static final String MESSAGE = "SUCCESS";
/**
* 状态
*/
@ApiModelProperty(value = "结果状态 [true成功;false失败]", dataType = "Boolean", required = true, example = "true")
private Boolean state;
/**
* 请求消息内容
*/
@ApiModelProperty(value = "结果描述", dataType = "String", required = true, example = MESSAGE)
private String message;
/**
* 返回值对象
*/
@ApiModelProperty(value = "结果数据", dataType = "Object", required = true)
private T body;
/**
* 异常栈
*/
@ApiModelProperty(value = "异常栈信息", dataType = "Throwable")
private Throwable cause;
private Response() {
}
public Boolean getState() {
return state;
}
private void setState(Boolean state) {
this.state = state;
}
public String getMessage() {
return message;
}
private void setMessage(String message) {
this.message = message;
}
public T getBody() {
return body;
}
private void setBody(T body) {
this.body = body;
}
public Throwable getCause() {
return cause;
}
private void setCause(Throwable cause) {
this.cause = cause;
}
/**
* 成功返回
* @param body 返回值
* @param 类型
* @return 响应
*/
public synchronized static Response success(T body) {
Response response = new Response<>();
response.setState(true);
response.setMessage(MESSAGE);
if (body != null) {
response.setBody(body);
}
response.setCause(null);
return response;
}
/**
* 失败返回
* @param apiError 错误代码
* @param cause 异常栈
* @return 响应
*/
public synchronized static Response
© 2015 - 2025 Weber Informatics LLC | Privacy Policy