全局异常捕获;参数校验
Sync All Branches to GitHub / sync (push) Successful in 2s

This commit is contained in:
2026-01-15 15:23:47 +08:00
parent f9613d2e01
commit 0f069433bc
18 changed files with 158 additions and 368 deletions
-21
View File
@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jy</groupId>
<artifactId>xiaoyishu</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.jy</groupId>
<artifactId>xiaoyi-framework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>平台基础设施层:封装一些常用功能,供各个业务线拿来即用</description>
<modules>
<module>xiaoyi-common</module>
<module>xiaoyi-spring-boot-starter-biz-operationlog</module>
<module>xiaoyi-spring-boot-starter-jackson</module>
</modules>
</project>
@@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jy</groupId>
<artifactId>xiaoyi-framework</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.jy</groupId>
<artifactId>xiaoyi-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>平台基础设施层:封装一些常用功能,供各个业务线拿来即用</description>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies>
</project>
+10 -1
View File
@@ -42,12 +42,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- jansi -->
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
</dependency>
<!-- 参数校验 -->
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
</project>
@@ -14,13 +14,13 @@ public interface BaseExceptionInterface {
*
* @return 异常码
*/
String getCode();
String getErrorCode();
/**
* 获取异常信息
*
* @return 异常信息
*/
String getMessage();
String getErrorMessage();
}
@@ -18,12 +18,12 @@ public class BizException extends RuntimeException {
/**
* 异常码
*/
private String code;
private String errorCode;
/**
* 异常信息
*/
private String message;
private String errorMessage;
/**
* 构造函数
@@ -31,8 +31,8 @@ public class BizException extends RuntimeException {
* @param baseExceptionInterface 基础异常接口
*/
public BizException(BaseExceptionInterface baseExceptionInterface) {
this.code = baseExceptionInterface.getCode();
this.message = baseExceptionInterface.getMessage();
this.errorCode = baseExceptionInterface.getErrorCode();
this.errorMessage = baseExceptionInterface.getErrorMessage();
}
}
@@ -2,6 +2,7 @@ package com.jy.framework.common.response;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import com.jy.framework.common.exception.BaseExceptionInterface;
@@ -31,6 +32,11 @@ public class Response<T> implements Serializable {
*/
private String message;
/**
* 响应时间
*/
private LocalDateTime time = LocalDateTime.now();
/**
* 是否成功
*/
@@ -110,8 +116,8 @@ public class Response<T> implements Serializable {
public static <T> Response<T> failure(BizException bizException) {
Response<T> response = new Response<>();
response.setSuccess(false);
response.setCode(bizException.getCode());
response.setMessage(bizException.getMessage());
response.setCode(bizException.getErrorCode());
response.setMessage(bizException.getErrorMessage());
return response;
}
@@ -125,8 +131,8 @@ public class Response<T> implements Serializable {
public static <T> Response<T> failure(BaseExceptionInterface baseExceptionInterface) {
Response<T> response = new Response<>();
response.setSuccess(false);
response.setCode(baseExceptionInterface.getCode());
response.setMessage(baseExceptionInterface.getMessage());
response.setCode(baseExceptionInterface.getErrorCode());
response.setMessage(baseExceptionInterface.getErrorMessage());
return response;
}
}
@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jy</groupId>
<artifactId>xiaoyi-framework</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.jy</groupId>
<artifactId>xiaoyi-spring-boot-starter-biz-operationlog</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>平台基础设施层:操作日志记录器</description>
<dependencies>
<dependency>
<groupId>com.jy</groupId>
<artifactId>xiaoyi-common</artifactId>
</dependency>
</dependencies>
</project>
@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jy</groupId>
<artifactId>xiaoyi-framework</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.jy</groupId>
<artifactId>xiaoyi-spring-boot-starter-jackson</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>平台基础设施层:Jackson 配置</description>
<dependencies>
<dependency>
<groupId>com.jy</groupId>
<artifactId>xiaoyi-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
</project>