BEST_MATCHING_HANDLER_ATTRIBUTE for spring-webmvc

Issue: SPR-17518
This commit is contained in:
Rossen Stoyanchev
2018-11-20 22:31:02 -05:00
parent d6a5c3428b
commit a55ca56e34
5 changed files with 23 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,6 +55,13 @@ import org.springframework.lang.Nullable;
*/
public interface HandlerMapping {
/**
* Name of the {@link HttpServletRequest} attribute that contains the mapped
* handler for the best matching pattern.
* @since 5.1.3
*/
String BEST_MATCHING_HANDLER_ATTRIBUTE = HandlerMapping.class.getName() + ".bestMatchingHandler";
/**
* Name of the {@link HttpServletRequest} attribute that contains the path
* within the handler mapping, in case of a pattern match, or the full

View File

@@ -414,6 +414,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
"Ambiguous handler methods mapped for '" + uri + "': {" + m1 + ", " + m2 + "}");
}
}
request.setAttribute(BEST_MATCHING_HANDLER_ATTRIBUTE, bestMatch.handlerMethod);
handleMatch(bestMatch.mapping, lookupPath, request);
return bestMatch.handlerMethod;
}

View File

@@ -411,6 +411,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
exposePathWithinMapping(this.bestMatchingPattern, this.pathWithinMapping, request);
request.setAttribute(BEST_MATCHING_HANDLER_ATTRIBUTE, handler);
request.setAttribute(INTROSPECT_TYPE_LEVEL_MAPPING, supportsTypeLevelMappings());
return true;
}