build: 返回实体封装 ResultHolder 中增加一个详细信息的字段

This commit is contained in:
CaptainB 2023-06-01 16:30:51 +08:00 committed by 刘瑞斌
parent 24d30b7f52
commit 8d72493908
1 changed files with 18 additions and 7 deletions

View File

@ -1,15 +1,15 @@
package io.metersphere.sdk.controller.handler;
import lombok.Data;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@Data
public class ResultHolder {
// 请求是否成功
private int code = 0;
// 描述信息
// 描述信息一般是错误信息
private String message;
// 详细描述信息, 如有异常这里是详细日志
private String messageDetail;
// 返回数据
private Object data = "";
@ -33,6 +33,13 @@ public class ResultHolder {
this.data = data;
}
public ResultHolder(int code, String msg, String messageDetail, Object data) {
this.code = code;
this.message = msg;
this.messageDetail = messageDetail;
this.data = data;
}
public static ResultHolder success(Object obj) {
return new ResultHolder(obj);
}
@ -41,11 +48,15 @@ public class ResultHolder {
return new ResultHolder(code, message, null);
}
public static ResultHolder error(int code, String message, Object object) {
return new ResultHolder(code, message, object);
public static ResultHolder error(int code, String message, Object data) {
return new ResultHolder(code, message, data);
}
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
public static ResultHolder error(String message, String messageDetail) {
return new ResultHolder(-1, message, messageDetail, null);
}
public static ResultHolder error(int code, String message, String messageDetail) {
return new ResultHolder(code, message, messageDetail, null);
}
}