1、增加处理 BadSqlGrammarException 异常
This commit is contained in:
@@ -12,6 +12,7 @@ import org.springframework.context.support.DefaultMessageSourceResolvable;
|
|||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
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.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
@@ -126,8 +127,8 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
// 处理 SQLSyntaxErrorException 异常
|
// 处理 SQLSyntaxErrorException 异常
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(SQLSyntaxErrorException.class)
|
@ExceptionHandler(value = BadSqlGrammarException.class)
|
||||||
public ResponseResult handleSQLSyntaxErrorException(SQLSyntaxErrorException ex) {
|
public ResponseResult handleSQLSyntaxErrorException(BadSqlGrammarException ex) {
|
||||||
// 打印异常日志
|
// 打印异常日志
|
||||||
// ex.printStackTrace();
|
// ex.printStackTrace();
|
||||||
log.error("遭遇 SQL 语法错误:{}", ex.getMessage());
|
log.error("遭遇 SQL 语法错误:{}", ex.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user