格式化代码。

main
ZhouXY108 2023-06-08 14:40:49 +08:00
parent c2735937cd
commit 3d2188199c
2 changed files with 13 additions and 16 deletions

View File

@ -6,7 +6,6 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;

View File

@ -52,25 +52,23 @@ public class WebMvcConfig implements WebMvcConfigurer, CommandLineRunner {
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
try { try {
RequestMappingHandlerMapping mapping = MfpContextHolder.getBean(RequestMappingHandlerMapping.class); RequestMappingHandlerMapping mapping = MfpContextHolder.getBean(RequestMappingHandlerMapping.class);
//获取url与类和方法的对应信息 // 获取url与类和方法的对应信息
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods(); Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
for (RequestMappingInfo info : map.keySet()) { for (RequestMappingInfo info : map.keySet()) {
// 获取url // 获取url
PatternsRequestCondition pathPatternsCondition = info.getPatternsCondition(); PatternsRequestCondition pathPatternsCondition = info.getPatternsCondition();
if (pathPatternsCondition != null) { Set<PathPattern> patterns = pathPatternsCondition.getPatterns()
Set<PathPattern> patterns = pathPatternsCondition.getPatterns() .stream()
.stream() .map(RequestUtils.defaultPathPatternParserInstance::parse)
.map(RequestUtils.defaultPathPatternParserInstance::parse) .collect(Collectors.toSet());
.collect(Collectors.toSet()); for (PathPattern pattern : patterns) {
for (PathPattern pattern : patterns) { Class<? extends PathPattern> aClass = pattern.getClass();
Class<? extends PathPattern> aClass = pattern.getClass(); Field field = aClass.getDeclaredField("capturedVariableCount");
Field field = aClass.getDeclaredField("capturedVariableCount"); field.setAccessible(true);
field.setAccessible(true); int num = (int) field.get(pattern);
int num = (int) field.get(pattern); // 不为0说明路径包含@PathVariable变量
//不为0说明路径包含@PathVariable变量 if (num != 0) {
if (num != 0) { patternList.add(pattern);
patternList.add(pattern);
}
} }
} }
} }