获取springMVC中所有URL Mapping
作者:
程序员老帮菜 | 来源:发表于
2020-06-18 09:29 被阅读0次 @Resource
private RequestMappingHandlerMapping handlerMapping;
public void getAllRequestMapping(){
// 所有URL mapping
List<String> requestMappingList = new ArrayList<>();
Map<RequestMappingInfo, HandlerMethod> requestMappingInfoHandlerMethodMap = this.handlerMapping.getHandlerMethods();
Optional.ofNullable(requestMappingInfoHandlerMethodMap).ifPresent(map -> {
map.forEach((requestMappingInfo, handlerMethod) -> {
Optional.ofNullable(requestMappingInfo.getPatternsCondition()).ifPresent(patternsRequestCondition -> {
Optional.ofNullable(patternsRequestCondition.getPatterns()).ifPresent(set -> {
set.forEach(s ->{
// 解决rest方式 占位符问题 /home/get/{id} 替换为 /home/get/
String url = s.replaceAll("\\{.*\\}", "");
if(StringUtils.hasLength(url)){
requestMappingList.add(url);
}
}
);
});
});
});
});
}
本文标题:获取springMVC中所有URL Mapping
本文链接:https://www.haomeiwen.com/subject/aepyxktx.html
网友评论