BEST_MATCHING_HANDLER_ATTRIBUTE for spring-webmvc
Issue: SPR-17518
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user