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); + } +}