From 6d870cb817e5942df5ee6ccda29db8dc44c6ba97 Mon Sep 17 00:00:00 2001 From: Wonder Date: Sat, 18 Oct 2025 14:30:40 +0800 Subject: [PATCH] =?UTF-8?q?=20=F0=9F=94=84Update:=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=8C=85=E8=A3=85=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hezhaohui/thumb/common/BaseResponse.java | 32 +++++++++++++++++++ .../hezhaohui/thumb/common/ResultUtils.java | 22 +++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/java/cn/hezhaohui/thumb/common/BaseResponse.java create mode 100644 src/main/java/cn/hezhaohui/thumb/common/ResultUtils.java diff --git a/src/main/java/cn/hezhaohui/thumb/common/BaseResponse.java b/src/main/java/cn/hezhaohui/thumb/common/BaseResponse.java new file mode 100644 index 0000000..731f82a --- /dev/null +++ b/src/main/java/cn/hezhaohui/thumb/common/BaseResponse.java @@ -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 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()); + } +} diff --git a/src/main/java/cn/hezhaohui/thumb/common/ResultUtils.java b/src/main/java/cn/hezhaohui/thumb/common/ResultUtils.java new file mode 100644 index 0000000..e725071 --- /dev/null +++ b/src/main/java/cn/hezhaohui/thumb/common/ResultUtils.java @@ -0,0 +1,22 @@ +package cn.hezhaohui.thumb.common; + +import cn.hezhaohui.thumb.exception.ErrorCode; + +public class ResultUtils { + + public static BaseResponse 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); + } +}