From a08ac338c090b8b27804a19deab1e62bdd550695 Mon Sep 17 00:00:00 2001 From: theo <971366405@qq.com> Date: Thu, 16 Oct 2025 10:25:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(security):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E8=BF=87=E6=BB=A4=E5=99=A8=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=8C=B9=E9=85=8D=E5=99=A8=E5=AE=9E=E7=8E=B0-=20?= =?UTF-8?q?=E5=B0=86=20AntPathRequestMatcher=20=E6=9B=BF=E6=8D=A2=E4=B8=BA?= =?UTF-8?q?=20PathPatternRequestMatcher-=20=E4=BD=BF=E7=94=A8=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E5=8C=B9=E9=85=8D=E5=99=A8=E5=B7=A5=E5=8E=82=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=88=9B=E5=BB=BA=E7=99=BB=E5=BD=95=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=99=A8-=E4=BF=9D=E6=8C=81=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91=E4=B8=8D?= =?UTF-8?q?=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(web): 设置响应字符编码为UTF-8 - 添加 StandardCharsets 导入- 在响应处理中显式设置字符编码 - 确保响应内容正确编码避免乱码问题 --- .../java/com/youlai/boot/core/web/WebResponseHelper.java | 4 +++- .../youlai/boot/security/filter/CaptchaValidationFilter.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/youlai/boot/core/web/WebResponseHelper.java b/src/main/java/com/youlai/boot/core/web/WebResponseHelper.java index 00ad93f2..192ec058 100644 --- a/src/main/java/com/youlai/boot/core/web/WebResponseHelper.java +++ b/src/main/java/com/youlai/boot/core/web/WebResponseHelper.java @@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import java.nio.charset.StandardCharsets; + /** * Web响应辅助类 *
@@ -40,7 +42,7 @@ public class WebResponseHelper { // 设置HTTP状态码 int httpStatus = mapHttpStatus(resultCode); response.setStatus(httpStatus); - + response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); // 构建响应对象 Result> result = message == null ? Result.failed(resultCode) diff --git a/src/main/java/com/youlai/boot/security/filter/CaptchaValidationFilter.java b/src/main/java/com/youlai/boot/security/filter/CaptchaValidationFilter.java index 771a7555..f0a08976 100644 --- a/src/main/java/com/youlai/boot/security/filter/CaptchaValidationFilter.java +++ b/src/main/java/com/youlai/boot/security/filter/CaptchaValidationFilter.java @@ -12,7 +12,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.HttpMethod; -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; import org.springframework.web.filter.OncePerRequestFilter; import java.io.IOException; @@ -26,7 +27,7 @@ import java.io.IOException; */ public class CaptchaValidationFilter extends OncePerRequestFilter { - private static final AntPathRequestMatcher LOGIN_PATH_REQUEST_MATCHER = new AntPathRequestMatcher(SecurityConstants.LOGIN_PATH, HttpMethod.POST.name()); + private static final RequestMatcher LOGIN_PATH_REQUEST_MATCHER = PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.POST,SecurityConstants.LOGIN_PATH); public static final String CAPTCHA_CODE_PARAM_NAME = "captchaCode"; public static final String CAPTCHA_KEY_PARAM_NAME = "captchaKey";