2、自定义Jackson starter
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>top.crushtj</groupId>
|
||||
<groupId>com.jy</groupId>
|
||||
<artifactId>xiaoyi-framework</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
@@ -36,6 +36,12 @@
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- AOP 切面 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
package top.crushtj.framework.common.constant;
|
||||
package com.jy.framework.common.constant;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @Title: DateConstants
|
||||
* @Description: 日期常量
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/26
|
||||
* @author ayi
|
||||
* @title DateConstants
|
||||
* @description 日期常量
|
||||
* @date 2025/11/26
|
||||
*/
|
||||
public interface DateConstants {
|
||||
/**
|
||||
@@ -27,5 +27,5 @@ public interface DateConstants {
|
||||
/**
|
||||
* DateTimeFormatter:年-月
|
||||
*/
|
||||
DateTimeFormatter DATE_FORMAT_Y_M = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||
DateTimeFormatter DATE_FORMAT_Y_M = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.jy.framework.common.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title BaseExceptionInterface
|
||||
* @description 基础异常接口
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
|
||||
public interface BaseExceptionInterface {
|
||||
/**
|
||||
* 获取异常码
|
||||
*
|
||||
* @return 异常码
|
||||
*/
|
||||
String getCode();
|
||||
|
||||
/**
|
||||
* 获取异常信息
|
||||
*
|
||||
* @return 异常信息
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.jy.framework.common.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title BusiException
|
||||
* @description 业务异常
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class BizException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* 异常码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param baseExceptionInterface 基础异常接口
|
||||
*/
|
||||
public BizException(BaseExceptionInterface baseExceptionInterface) {
|
||||
this.code = baseExceptionInterface.getCode();
|
||||
this.message = baseExceptionInterface.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package com.jy.framework.common.response;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import com.jy.framework.common.exception.BaseExceptionInterface;
|
||||
import com.jy.framework.common.exception.BizException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ayi
|
||||
* @title Response
|
||||
* @description 响应体
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class Response<T> implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = -6624218097474846897L;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 响应信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*/
|
||||
private boolean success = true;
|
||||
|
||||
/**
|
||||
* 响应数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @return 成功响应
|
||||
*/
|
||||
public static <T> Response<T> success() {
|
||||
return new Response<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @param data 响应数据
|
||||
* @return 成功响应
|
||||
*/
|
||||
public static <T> Response<T> success(T data) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setData(data);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure() {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param message 异常信息
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(String message) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param code 异常码
|
||||
* @param message 异常信息
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(String code, String message) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(code);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param bizException 业务异常
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(BizException bizException) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(bizException.getCode());
|
||||
response.setMessage(bizException.getMessage());
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param <T> 响应数据类型
|
||||
* @param baseExceptionInterface 基础异常
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(BaseExceptionInterface baseExceptionInterface) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(baseExceptionInterface.getCode());
|
||||
response.setMessage(baseExceptionInterface.getMessage());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package top.crushtj.framework.common.utils;
|
||||
package com.jy.framework.common.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -8,10 +8,10 @@ import lombok.SneakyThrows;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: JsonUtils
|
||||
* @Description: JSON 工具类
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/21
|
||||
* @author ayi
|
||||
* @title JsonUtils
|
||||
* @description JSON 工具类
|
||||
* @date 2025/11/21
|
||||
*/
|
||||
public class JsonUtils {
|
||||
private static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package top.crushtj.framework.common.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: BaseExceptionInterface
|
||||
* @Description: 基础异常接口
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/20
|
||||
*/
|
||||
|
||||
public interface BaseExceptionInterface {
|
||||
/**
|
||||
* 获取异常码
|
||||
*
|
||||
* @return 异常码
|
||||
*/
|
||||
String getCode();
|
||||
|
||||
/**
|
||||
* 获取异常信息
|
||||
*
|
||||
* @return 异常信息
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
package top.crushtj.framework.common.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: BusiException
|
||||
* @Description: 业务异常
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/20
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class BizException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* 异常码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param baseExceptionInterface 基础异常接口
|
||||
*/
|
||||
public BizException(BaseExceptionInterface baseExceptionInterface) {
|
||||
this.code = baseExceptionInterface.getCode();
|
||||
this.message = baseExceptionInterface.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
package top.crushtj.framework.common.response;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import top.crushtj.framework.common.exception.BaseExceptionInterface;
|
||||
import top.crushtj.framework.common.exception.BizException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Title: Response
|
||||
* @Description: 响应体
|
||||
* @Author: ayi
|
||||
* @Date: 2025/11/20
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class Response<T> implements Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -6624218097474846897L;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 响应信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*/
|
||||
private boolean success = true;
|
||||
|
||||
/**
|
||||
* 响应数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @return 成功响应
|
||||
*/
|
||||
public static <T> Response<T> success() {
|
||||
return new Response<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @param data 响应数据
|
||||
* @return 成功响应
|
||||
*/
|
||||
public static <T> Response<T> success(T data) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setData(data);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure() {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param message 异常信息
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(String message) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param code 异常码
|
||||
* @param message 异常信息
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(String code, String message) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(code);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param bizException 业务异常
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(BizException bizException) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(bizException.getCode());
|
||||
response.setMessage(bizException.getMessage());
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param <T>
|
||||
* @param baseExceptionInterface 基础异常
|
||||
* @return 失败响应
|
||||
*/
|
||||
public static <T> Response<T> failure(BaseExceptionInterface baseExceptionInterface) {
|
||||
Response<T> response = new Response<>();
|
||||
response.setSuccess(false);
|
||||
response.setCode(baseExceptionInterface.getCode());
|
||||
response.setMessage(baseExceptionInterface.getMessage());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user