Aşağıdaki kod, @Controller
sınıflarındaki tür ve yöntem düzeyindeki @RequestMapping
ek açıklamalardan tüm RequestMappingInfo
örneklerini ayıklar.
// context = ApplicationContext
Map<String, RequestMappingHandlerMapping> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context,
RequestMappingHandlerMapping.class, true, false);
if (!matchingBeans.isEmpty()) {
ArrayList<HandlerMapping> handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
AnnotationAwareOrderComparator.sort(handlerMappings);
RequestMappingHandlerMapping mappings = matchingBeans.get("requestMappingHandlerMapping");
Map<RequestMappingInfo, HandlerMethod> handlerMethods = mappings.getHandlerMethods();
for (RequestMappingInfo requestMappingInfo : handlerMethods.keySet()) {
RequestMethodsRequestCondition methods = requestMappingInfo.getMethodsCondition();
// Get all requestMappingInfos with
// 1) default request-method (which is none)
// 2) or method=GET
if (methods.getMethods().isEmpty() || methods.getMethods().contains(RequestMethod.GET)) {
System.out.println(requestMappingInfo.getPatternsCondition().getPatterns() + " -> produces " +
requestMappingInfo.getProducesCondition());
}
}
}
Muhtemelen hata sayfaları için eşlemeleri filtrelemeniz gerekir. RequestMappingInfo
nesne gibi @RequestMapping
üzerinde ek açıklamalar tanımlar olduğunu ilgili tüm haritalama bilgileri içerir: ->@RequestMapping(method=RequestMethod.GET)
RequestMappingInfo.getPatternsCondition().getPatterns()
-
RequestMappingInfo.getMethods()
Daha fazla ayrıntı>@RequestMapping(value = "/foo")
- vb
RequestMappingInfo
Daha fazla c için ör. ViewController yapılandırmaları, hem de sen SimpleUrlHandlerMapping
türü için filtre gerekir:
Map<String, SimpleUrlHandlerMapping> matchingUrlHandlerMappingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context,
SimpleUrlHandlerMapping.class, true, false);
SimpleUrlHandlerMapping mappings = matchingUrlHandlerMappingBeans.get("viewControllerHandlerMapping");
System.out.println(mappings.getUrlMap());
Çok teşekkür ederim :) – Richard
yardım edebilirim sevindim! – fateddy