基础操作配置
This commit is contained in:
parent
0cae354f47
commit
51441277a6
6
pom.xml
6
pom.xml
@ -65,6 +65,12 @@
|
||||
<version>3.0.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>24.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -0,0 +1,37 @@
|
||||
package org.xlf.function.resourcesdocking.common.util;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* <h1>BaseResponse 基础响应类</h1>
|
||||
* <hr/>
|
||||
* 用于封装响应数据
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package org.xlf.function.resourcesdocking.common.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* <h1>ResultUtil 响应结果工具类</h1>
|
||||
* <hr/>
|
||||
* 用于封装响应结果
|
||||
*
|
||||
* @author 筱锋xiao_lfeng
|
||||
* @version v1.0.0
|
||||
* @see BaseResponse
|
||||
* @since v1.0.0
|
||||
*/
|
||||
public class ResultUtil {
|
||||
|
||||
/**
|
||||
* <h2>Success 成功响应结果</h2>
|
||||
* <hr/>
|
||||
* 用于封装成功响应结果
|
||||
*
|
||||
* @return BaseResponse
|
||||
*/
|
||||
public static @NotNull BaseResponse success() {
|
||||
return new BaseResponse("Success", 200, "操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>Success 成功响应结果</h2>
|
||||
* <hr/>
|
||||
* 用于封装成功响应结果
|
||||
*
|
||||
* @param data 响应数据
|
||||
* @return BaseResponse
|
||||
*/
|
||||
public static @NotNull BaseResponse success(Object data) {
|
||||
return new BaseResponse("Success", 200, "操作成功", data);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>Success 成功响应结果</h2>
|
||||
* <hr/>
|
||||
* 用于封装成功响应结果
|
||||
*
|
||||
* @param output 输出信息
|
||||
* @param message 响应信息
|
||||
* @return BaseResponse
|
||||
*/
|
||||
public static @NotNull BaseResponse success(String output, String message) {
|
||||
return new BaseResponse(output, 200, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>Success 成功响应结果</h2>
|
||||
* <hr/>
|
||||
* 用于封装成功响应结果
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>Error 错误响应结果</h2>
|
||||
* <hr/>
|
||||
* 用于封装错误响应结果
|
||||
*
|
||||
* @param errorCode 错误码
|
||||
* @return BaseResponse
|
||||
*/
|
||||
public static @NotNull BaseResponse error(@NotNull ErrorCode errorCode) {
|
||||
return new BaseResponse(errorCode.getOutput(), errorCode.getCode(), errorCode.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>Error 错误响应结果</h2>
|
||||
* <hr/>
|
||||
* 用于封装错误响应结果
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
@ -1 +1,6 @@
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306
|
||||
username: srd
|
||||
password: 123456
|
Loading…
x
Reference in New Issue
Block a user