update 优化 获取系统url存储重复问题

feature/model
疯狂的狮子li 2 years ago
parent 7c5d645639
commit 37290d023e

@ -8,10 +8,7 @@ import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
@ -28,16 +25,18 @@ public class AllUrlHandler implements InitializingBean {
@Override @Override
public void afterPropertiesSet() { public void afterPropertiesSet() {
Set<String> set = new HashSet<>();
RequestMappingHandlerMapping mapping = SpringUtils.getBean("requestMappingHandlerMapping", RequestMappingHandlerMapping.class); RequestMappingHandlerMapping mapping = SpringUtils.getBean("requestMappingHandlerMapping", RequestMappingHandlerMapping.class);
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods(); Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
map.keySet().forEach(info -> { map.keySet().forEach(info -> {
// 获取方法上边的注解 替代path variable 为 * // 获取方法上边的注解 替代path variable 为 *
Objects.requireNonNull(info.getPathPatternsCondition().getPatterns()) Objects.requireNonNull(info.getPathPatternsCondition().getPatterns())
.forEach(url -> urls.add(ReUtil.replaceAll(url.getPatternString(), PATTERN, "*"))); .forEach(url -> set.add(ReUtil.replaceAll(url.getPatternString(), PATTERN, "*")));
// 获取类上边的注解, 替代path variable 为 * // 获取类上边的注解, 替代path variable 为 *
Objects.requireNonNull(info.getPathPatternsCondition().getPatterns()) Objects.requireNonNull(info.getPathPatternsCondition().getPatterns())
.forEach(url -> urls.add(ReUtil.replaceAll(url.getPatternString(), PATTERN, "*"))); .forEach(url -> set.add(ReUtil.replaceAll(url.getPatternString(), PATTERN, "*")));
}); });
urls.addAll(set);
} }
} }

Loading…
Cancel
Save