AnnotationMethodHandlerAdapter.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:spring4-understanding 作者:
public Method resolveHandlerMethod(PortletRequest request) throws PortletException {
    Map<RequestMappingInfo, Method> targetHandlerMethods = new LinkedHashMap<RequestMappingInfo, Method>();
    for (Method handlerMethod : getHandlerMethods()) {
        RequestMappingInfo mappingInfo = this.mappings.get(handlerMethod);
        if (mappingInfo.match(request)) {
            Method oldMappedMethod = targetHandlerMethods.put(mappingInfo, handlerMethod);
            if (oldMappedMethod != null && oldMappedMethod != handlerMethod) {
                throw new IllegalStateException("Ambiguous handler methods mapped for portlet mode '" +
                        request.getPortletMode() + "': {" + oldMappedMethod + ", " + handlerMethod +
                        "}. If you intend to handle the same mode in multiple methods, then factor " +
                        "them out into a dedicated handler class with that mode mapped at the type level!");
            }
        }
    }
    if (!targetHandlerMethods.isEmpty()) {
        if (targetHandlerMethods.size() == 1) {
            return targetHandlerMethods.values().iterator().next();
        }
        else {
            RequestMappingInfo bestMappingMatch = null;
            for (RequestMappingInfo mapping : targetHandlerMethods.keySet()) {
                if (bestMappingMatch == null) {
                    bestMappingMatch = mapping;
                }
                else {
                    if (mapping.isBetterMatchThan(bestMappingMatch)) {
                        bestMappingMatch = mapping;
                    }
                }
            }
            return targetHandlerMethods.get(bestMappingMatch);
        }
    }
    else {
        throw new NoHandlerFoundException("No matching handler method found for portlet request", request);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号