From 8905e232e5fee135161bff20af0802c38ba08a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 26 Sep 2025 11:19:48 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20mybatis=E5=86=85?= =?UTF-8?q?=E6=8A=A5token=E5=BC=82=E5=B8=B8=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E8=BF=94=E5=9B=9E=E5=89=8D=E7=AB=AF=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/mybatis/handler/MybatisExceptionHandler.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/MybatisExceptionHandler.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/MybatisExceptionHandler.java index 9a572b56b..28b14c226 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/MybatisExceptionHandler.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/MybatisExceptionHandler.java @@ -5,7 +5,9 @@ import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.domain.R; import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.satoken.handler.SaTokenExceptionHandler; import org.mybatis.spring.MyBatisSystemException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DuplicateKeyException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -19,6 +21,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; @RestControllerAdvice public class MybatisExceptionHandler { + @Autowired + private SaTokenExceptionHandler saTokenExceptionHandler; + /** * 主键或UNIQUE索引,数据重复异常 */ @@ -40,6 +45,10 @@ public class MybatisExceptionHandler { log.error("请求地址'{}', 未找到数据源", requestURI); return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, "未找到数据源,请联系管理员确认"); } + if (StringUtils.contains(message, "NotLoginException")) { + log.error("请求地址'{}',认证失败'{}',无法访问系统资源", requestURI, e.getMessage()); + return R.fail(HttpStatus.HTTP_UNAUTHORIZED, "认证失败,无法访问系统资源"); + } log.error("请求地址'{}', Mybatis系统异常", requestURI, e); return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, message); }