diff --git a/src/main/java/com/cultural/heritage/common/ErrorCode.java b/src/main/java/com/cultural/heritage/common/ErrorCode.java index d6f135b..e9f14a1 100644 --- a/src/main/java/com/cultural/heritage/common/ErrorCode.java +++ b/src/main/java/com/cultural/heritage/common/ErrorCode.java @@ -13,6 +13,7 @@ public enum ErrorCode { FORBIDDEN_ERROR(40300,"禁止访问"), SYSTEM_ERROR(50000,"系统内部异常"), OPERATION_ERROR(50001,"操作失败"), + DATABASE_ERROR(50002, "数据库内部异常"), LOGIN_ERROR(40110,"登陆状态变更"); /** diff --git a/src/main/java/com/cultural/heritage/exception/GlobalExceptionHandler.java b/src/main/java/com/cultural/heritage/exception/GlobalExceptionHandler.java index 60c77cc..f031eca 100644 --- a/src/main/java/com/cultural/heritage/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/cultural/heritage/exception/GlobalExceptionHandler.java @@ -4,9 +4,12 @@ import com.cultural.heritage.common.BaseResponse; import com.cultural.heritage.common.ErrorCode; import com.cultural.heritage.common.ResultUtils; import lombok.extern.slf4j.Slf4j; +import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import java.sql.SQLException; + /** * 全局异常处理器 */ @@ -20,9 +23,26 @@ public class GlobalExceptionHandler { return ResultUtils.error(e.getCode(), e.getMessage()); } + // 处理SQL异常(SQLException) + @ExceptionHandler(SQLException.class) + public BaseResponse sqlExceptionHandler(SQLException e) { + log.error("SQL error", e); + return ResultUtils.error(ErrorCode.DATABASE_ERROR, "数据库操作失败,请检查SQL语句"); + } + + + // 处理数据库连接异常(CannotGetJdbcConnectionException) + @ExceptionHandler(CannotGetJdbcConnectionException.class) + public BaseResponse jdbcConnectionExceptionHandler(CannotGetJdbcConnectionException e) { + log.error("Database connection error", e); + return ResultUtils.error(ErrorCode.DATABASE_ERROR, "无法连接到数据库,请检查数据库连接配置"); + } + + @ExceptionHandler(RuntimeException.class) public BaseResponse runtimeExceptionHandler(RuntimeException e) { log.error("RuntimeException", e); return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "系统错误"); } + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0cfdc9d..180155a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,7 +3,7 @@ spring: # 生产环境 driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://154.8.193.216:3306/feiyi?serverTimezone=Asia/Shanghai - username: feiyi + username: feiyi0 password: 123456asd hikari: maximum-pool-size: 20 diff --git a/src/main/resources/mapper/AppointmentDateMapper.xml b/src/main/resources/mapper/AppointmentDateMapper.xml index 23efc35..b2c696d 100644 --- a/src/main/resources/mapper/AppointmentDateMapper.xml +++ b/src/main/resources/mapper/AppointmentDateMapper.xml @@ -6,7 +6,7 @@