public class ResultVO<T> {
private Integer code;
private String msg;
private T data;
/**
* 无参构造方法
*/
public ResultVO() {
}
/**
* @param code restful调用结果代码
* @param msg restful调用结果消息
* @param data 数据
*/
public ResultVO(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
/**
*
* @param code restful调用结果代码
* @param msg restful调用结果消息
*/
public ResultVO(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
/**
* 创建新的实例
* @param stauts restful调用结果代码 http 状态码
* @param msg restful调用结果消息
* @param data 数据
* @return
*/
public static <T> ResultVO<T> newInst(Status stauts, String msg, T data) {
return new ResultVO<>(stauts.getStatusCode(), msg, data);
}
/**
* 创建新的实例
* @param code restful调用结果代码
* @param msg restful调用结果消息
* @param data 数据
* @return
*/
public static <T> ResultVO<T> newInst(Integer code, String msg, T data) {
return new ResultVO<>(code, msg, data);
}
/**
* 创建新的实例
* @param stauts restful调用结果代码 http 状态码
* @param message restful调用结果消息
* @return
*/
public static <T> ResultVO<T> newInst(HttpStatus stauts, String message) {
return new ResultVO<>(stauts.value(), message);
}
public static <T> ResultVO<T> newInst(HttpStatus stauts, String message, T data) {
return new ResultVO<>(stauts.value(), message, data);
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
public String toJsonString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}