From c0fe137c48e391bb3a50ec2f352bc45de9ddb584 Mon Sep 17 00:00:00 2001 From: cat_shark <1716967236@qq.com> Date: Sat, 4 Jul 2026 17:38:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=90=8E=E7=AB=AF)=EF=BC=9A@Transactional?= =?UTF-8?q?=20+=20WebMvcProdConfig=20OPTIONS=20=E8=B7=B3=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - WebMvcProdConfig:SaInterceptor 增加 OPTIONS 预检跳过, 解决生产环境 CORS 预检 401 问题 - StudySessionsServiceImpl.endedStudySession/continueStudySession: 增加 @Transactional - StudyReportFragmentsServiceImpl.createFragments: 增加 @Transactional --- .../learningprogresstracker/config/WebMvcProdConfig.java | 8 +++++++- .../service/impl/StudyReportFragmentsServiceImpl.java | 2 ++ .../service/impl/StudySessionsServiceImpl.java | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/guo/learningprogresstracker/config/WebMvcProdConfig.java b/src/main/java/com/guo/learningprogresstracker/config/WebMvcProdConfig.java index 5b06508..4f45363 100644 --- a/src/main/java/com/guo/learningprogresstracker/config/WebMvcProdConfig.java +++ b/src/main/java/com/guo/learningprogresstracker/config/WebMvcProdConfig.java @@ -1,5 +1,6 @@ package com.guo.learningprogresstracker.config; +import cn.dev33.satoken.context.SaHolder; import cn.dev33.satoken.interceptor.SaInterceptor; import cn.dev33.satoken.stp.StpUtil; import lombok.RequiredArgsConstructor; @@ -32,7 +33,12 @@ public class WebMvcProdConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin())) + registry.addInterceptor(new SaInterceptor(handle -> { + if ("OPTIONS".equalsIgnoreCase(SaHolder.getRequest().getMethod())) { + return; + } + StpUtil.checkLogin(); + })) .addPathPatterns("/**") .excludePathPatterns("/login"); } diff --git a/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java b/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java index 5e54fc0..5378613 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java @@ -13,6 +13,7 @@ import com.guo.learningprogresstracker.service.StudyReportFragmentsService; import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -27,6 +28,7 @@ public class StudyReportFragmentsServiceImpl extends ServiceImpl