1、增加处理 BadSqlGrammarException 异常

This commit is contained in:
PushM
2024-06-10 23:39:04 +08:00
parent c1e0887d4a
commit e8d38b3c4b

View File

@@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.jdbc.BadSqlGrammarException;
@@ -136,4 +137,17 @@ public class GlobalExceptionHandler {
return ResponseResult.error().setMessage("数据库错误,错误的查询语法"); return ResponseResult.error().setMessage("数据库错误,错误的查询语法");
} }
@Order(2)
@ExceptionHandler(value = DataIntegrityViolationException.class)
public ResponseResult handleDataIntegrityViolationException(DataIntegrityViolationException ex) {
// 打印异常日志
// ex.printStackTrace();
log.error("遭遇 SQL 语法错误:{}", ex.getMessage());
return ResponseResult.error().setMessage("预删除对象正在被任务使用中,无法删除");
}
} }