🔄Update: 增加响应包装类

This commit is contained in:
2025-10-18 14:30:40 +08:00
parent 4a451278af
commit 6d870cb817
2 changed files with 54 additions and 0 deletions
@@ -0,0 +1,32 @@
package cn.hezhaohui.thumb.common;
import cn.hezhaohui.thumb.exception.ErrorCode;
import lombok.Data;
import java.io.Serializable;
@Data
public class BaseResponse<T> implements Serializable {
private int code;
private T data;
private String message;
public BaseResponse(int code, T data, String message) {
this.code = code;
this.data = data;
this.message = message;
}
public BaseResponse(int code, T data) {
this(code, data, "");
}
public BaseResponse(ErrorCode errorCode) {
this(errorCode.getCode(), null, errorCode.getMessage());
}
}
@@ -0,0 +1,22 @@
package cn.hezhaohui.thumb.common;
import cn.hezhaohui.thumb.exception.ErrorCode;
public class ResultUtils {
public static <T> BaseResponse<T> sucess(T data) {
return new BaseResponse<>(ErrorCode.SUCCESS.getCode(), data, ErrorCode.SUCCESS.getMessage());
}
public static BaseResponse<?> error(ErrorCode errorCode) {
return new BaseResponse<>(errorCode);
}
public static BaseResponse<?> error(int code, String message) {
return new BaseResponse<>(code, null, message);
}
public static BaseResponse<?> error(ErrorCode errorCode, String message) {
return new BaseResponse<>(errorCode.getCode(), null, message);
}
}