From 1cf148a66cfbe0442bbadb168e9340a261bf95c3 Mon Sep 17 00:00:00 2001 From: bai <1643359946@qq.com> Date: Wed, 26 Jun 2024 22:44:52 +0800 Subject: [PATCH] =?UTF-8?q?2024=E5=B9=B46=E6=9C=8826=E6=97=A5=20=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=EF=BC=8C=E9=9A=90?= =?UTF-8?q?=E8=97=8FSQL=E9=94=99=E8=AF=AF=EF=BC=8C=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E6=9C=AA=E6=B3=A8=E5=86=8C=E7=94=A8=E6=88=B7=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/JeecgBootExceptionHandler.java | 22 +++++++++++++++++-- .../service/impl/SysUserServiceImpl.java | 3 ++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java index 6d5d8ef7..8dfc6831 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java @@ -5,10 +5,11 @@ import org.apache.shiro.authz.AuthorizationException; import org.apache.shiro.authz.UnauthorizedException; import org.jeecg.common.api.vo.Result; import org.jeecg.common.enums.SentinelErrorInfoEnum; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.DuplicateKeyException; +import org.springframework.core.NestedRuntimeException; +import org.springframework.dao.*; import org.springframework.data.redis.connection.PoolException; import org.springframework.http.HttpStatus; +import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; @@ -18,6 +19,10 @@ import org.springframework.web.servlet.NoHandlerFoundException; import lombok.extern.slf4j.Slf4j; +import java.sql.SQLException; +import java.sql.SQLNonTransientException; +import java.sql.SQLSyntaxErrorException; + /** * 异常处理器 * @@ -133,4 +138,17 @@ public class JeecgBootExceptionHandler { return Result.error("Redis 连接异常!"); } + @ExceptionHandler({ SQLSyntaxErrorException.class, SQLNonTransientException.class, SQLException.class }) + public Result handleSQLSyntaxErrorException(SQLException e) { + log.error(e.getMessage(), e); + return Result.error("SQL语法错误!"); + } + + @ExceptionHandler({ BadSqlGrammarException.class, InvalidDataAccessResourceUsageException.class, NonTransientDataAccessException.class, DataAccessException.class }) + public Result handleBadSqlGrammarException(DataAccessException e) { + log.error(e.getMessage(), e); + return Result.error("SQL语法错误!"); + } + + } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java index 6e51e463..924a0b1c 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java @@ -528,7 +528,8 @@ public class SysUserServiceImpl extends ServiceImpl impl Result result = new Result(); //情况1:根据用户信息查询,该用户不存在 if (sysUser == null) { - result.error500("该用户不存在,请注册"); + //result.error500("该用户不存在,请注册");//不允许明确的提示 + result.error500("用户名或密码错误"); baseCommonService.addLog("用户登录失败,用户不存在!", CommonConstant.LOG_TYPE_1, null); return result; }