diff --git a/pom.xml b/pom.xml index 914e3a3..5e6b19c 100644 --- a/pom.xml +++ b/pom.xml @@ -65,6 +65,12 @@ 3.0.3 test + + org.jetbrains + annotations + 24.1.0 + compile + diff --git a/src/main/java/org/xlf/function/resourcesdocking/common/util/BaseResponse.java b/src/main/java/org/xlf/function/resourcesdocking/common/util/BaseResponse.java new file mode 100644 index 0000000..6679d8e --- /dev/null +++ b/src/main/java/org/xlf/function/resourcesdocking/common/util/BaseResponse.java @@ -0,0 +1,37 @@ +package org.xlf.function.resourcesdocking.common.util; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; + +/** + *

BaseResponse 基础响应类

+ *
+ * 用于封装响应数据 + * + * @since v1.0.0 + * @version v1.0.0 + * @author 筱锋xiao_lfeng + */ +@Getter +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BaseResponse { + + private final String output; + private final Integer code; + private final String message; + private final Object data; + + public BaseResponse(String output, Integer code, String message, Object data) { + this.output = output; + this.code = code; + this.message = message; + this.data = data; + } + + public BaseResponse(String output, Integer code, String message) { + this.output = output; + this.code = code; + this.message = message; + this.data = null; + } +} diff --git a/src/main/java/org/xlf/function/resourcesdocking/common/util/ErrorCode.java b/src/main/java/org/xlf/function/resourcesdocking/common/util/ErrorCode.java new file mode 100644 index 0000000..8e6fc96 --- /dev/null +++ b/src/main/java/org/xlf/function/resourcesdocking/common/util/ErrorCode.java @@ -0,0 +1,29 @@ +package org.xlf.function.resourcesdocking.common.util; + +import lombok.Getter; + +@Getter +public enum ErrorCode { + + /* + * 通用错误码 + */ + WRONG_PASSWORD("WrongPassword", 40000, "密码错误"), + USER_NOT_FOUND("UserNotFound", 40001, "用户不存在"), + USER_EXIST("UserExist", 40002, "用户已存在"), + USER_BAN("UserBan", 40003, "用户已被封禁"), + USER_VERIFY("UserVerify", 40004, "用户未通过验证"), + USER_NOT_LOGIN("UserNotLogin", 40005, "用户未登录"), + USER_NOT_PERMISSION("UserNotPermission", 40006, "用户无权限"), + USER_NOT_ACTIVE("UserNotActive", 40007, "用户未激活"); + + private final String output; + private final Integer code; + private final String message; + + ErrorCode(String output, Integer code, String message) { + this.output = output; + this.code = code; + this.message = message; + } +} diff --git a/src/main/java/org/xlf/function/resourcesdocking/common/util/ResultUtil.java b/src/main/java/org/xlf/function/resourcesdocking/common/util/ResultUtil.java new file mode 100644 index 0000000..cc9530e --- /dev/null +++ b/src/main/java/org/xlf/function/resourcesdocking/common/util/ResultUtil.java @@ -0,0 +1,92 @@ +package org.xlf.function.resourcesdocking.common.util; + +import org.jetbrains.annotations.NotNull; + +/** + *

ResultUtil 响应结果工具类

+ *
+ * 用于封装响应结果 + * + * @author 筱锋xiao_lfeng + * @version v1.0.0 + * @see BaseResponse + * @since v1.0.0 + */ +public class ResultUtil { + + /** + *

Success 成功响应结果

+ *
+ * 用于封装成功响应结果 + * + * @return BaseResponse + */ + public static @NotNull BaseResponse success() { + return new BaseResponse("Success", 200, "操作成功"); + } + + /** + *

Success 成功响应结果

+ *
+ * 用于封装成功响应结果 + * + * @param data 响应数据 + * @return BaseResponse + */ + public static @NotNull BaseResponse success(Object data) { + return new BaseResponse("Success", 200, "操作成功", data); + } + + /** + *

Success 成功响应结果

+ *
+ * 用于封装成功响应结果 + * + * @param output 输出信息 + * @param message 响应信息 + * @return BaseResponse + */ + public static @NotNull BaseResponse success(String output, String message) { + return new BaseResponse(output, 200, message); + } + + /** + *

Success 成功响应结果

+ *
+ * 用于封装成功响应结果 + * + * @param output 输出信息 + * @param message 响应信息 + * @param data 响应数据 + * @return BaseResponse + */ + public static @NotNull BaseResponse success(String output, String message, Object data) { + return new BaseResponse(output, 200, message, data); + } + + /** + *

Error 错误响应结果

+ *
+ * 用于封装错误响应结果 + * + * @param errorCode 错误码 + * @return BaseResponse + */ + public static @NotNull BaseResponse error(@NotNull ErrorCode errorCode) { + return new BaseResponse(errorCode.getOutput(), errorCode.getCode(), errorCode.getMessage()); + } + + /** + *

Error 错误响应结果

+ *
+ * 用于封装错误响应结果 + * + * @param output 输出信息 + * @param code 业务错误码 + * @param message 响应信息 + * @return BaseResponse + */ + public static @NotNull BaseResponse error(String output, Integer code, String message) { + return new BaseResponse(output, code, message); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8b13789..7481066 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1 +1,6 @@ - +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306 + username: srd + password: 123456 \ No newline at end of file