From 3d2188199c69bd805608946952bab352f7759f39 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Thu, 8 Jun 2023 14:40:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mfp/framework/config/SecurityConfig.java | 1 - .../mfp/framework/config/WebMvcConfig.java | 28 +++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/nantian/mfp/framework/config/SecurityConfig.java b/src/main/java/com/nantian/mfp/framework/config/SecurityConfig.java index 5d12553..8d1e1ce 100644 --- a/src/main/java/com/nantian/mfp/framework/config/SecurityConfig.java +++ b/src/main/java/com/nantian/mfp/framework/config/SecurityConfig.java @@ -6,7 +6,6 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; diff --git a/src/main/java/com/nantian/mfp/framework/config/WebMvcConfig.java b/src/main/java/com/nantian/mfp/framework/config/WebMvcConfig.java index 810ac2d..d2eba52 100644 --- a/src/main/java/com/nantian/mfp/framework/config/WebMvcConfig.java +++ b/src/main/java/com/nantian/mfp/framework/config/WebMvcConfig.java @@ -52,25 +52,23 @@ public class WebMvcConfig implements WebMvcConfigurer, CommandLineRunner { public void run(String... args) throws Exception { try { RequestMappingHandlerMapping mapping = MfpContextHolder.getBean(RequestMappingHandlerMapping.class); - //获取url与类和方法的对应信息 + // 获取url与类和方法的对应信息 Map map = mapping.getHandlerMethods(); for (RequestMappingInfo info : map.keySet()) { // 获取url PatternsRequestCondition pathPatternsCondition = info.getPatternsCondition(); - if (pathPatternsCondition != null) { - Set patterns = pathPatternsCondition.getPatterns() - .stream() - .map(RequestUtils.defaultPathPatternParserInstance::parse) - .collect(Collectors.toSet()); - for (PathPattern pattern : patterns) { - Class aClass = pattern.getClass(); - Field field = aClass.getDeclaredField("capturedVariableCount"); - field.setAccessible(true); - int num = (int) field.get(pattern); - //不为0说明路径包含@PathVariable变量 - if (num != 0) { - patternList.add(pattern); - } + Set patterns = pathPatternsCondition.getPatterns() + .stream() + .map(RequestUtils.defaultPathPatternParserInstance::parse) + .collect(Collectors.toSet()); + for (PathPattern pattern : patterns) { + Class aClass = pattern.getClass(); + Field field = aClass.getDeclaredField("capturedVariableCount"); + field.setAccessible(true); + int num = (int) field.get(pattern); + // 不为0说明路径包含@PathVariable变量 + if (num != 0) { + patternList.add(pattern); } } }