接口 HandlerMapping
- 所有已知子接口:
MatchableHandlerMapping
- 所有已知实现类:
AbstractControllerUrlHandlerMapping
,AbstractDetectingUrlHandlerMapping
,AbstractHandlerMapping
,AbstractHandlerMethodMapping
,AbstractUrlHandlerMapping
,BeanNameUrlHandlerMapping
,ControllerBeanNameHandlerMapping
,ControllerClassNameHandlerMapping
,DefaultAnnotationHandlerMapping
,RequestMappingHandlerMapping
,RequestMappingInfoHandlerMapping
,SimpleUrlHandlerMapping
,WebSocketHandlerMapping
public interface HandlerMapping
Interface to be implemented by objects that define a mapping between requests and handler objects.This class can be implemented by application developers, although this is not necessary, as
BeanNameUrlHandlerMapping
andDefaultAnnotationHandlerMapping
are included in the framework. The former is the default if no HandlerMapping bean is registered in the application context.HandlerMapping implementations can support mapped interceptors but do not have to. A handler will always be wrapped in a
HandlerExecutionChain
instance, optionally accompanied by someHandlerInterceptor
instances. The DispatcherServlet will first call each HandlerInterceptor'spreHandle
method in the given order, finally invoking the handler itself if allpreHandle
methods have returnedtrue
.The ability to parameterize this mapping is a powerful and unusual capability of this MVC framework. For example, it is possible to write a custom mapping based on session state, cookie state or many other variables. No other MVC framework seems to be equally flexible.
Note: Implementations can implement the
Ordered
interface to be able to specify a sorting order and thus a priority for getting applied by DispatcherServlet. Non-Ordered instances get treated as lowest priority.- 作者:
- Rod Johnson, Juergen Hoeller
- 另请参阅:
Ordered
,AbstractHandlerMapping
,BeanNameUrlHandlerMapping
,DefaultAnnotationHandlerMapping
字段概要
字段 修饰符和类型 字段 说明 static String
BEST_MATCHING_HANDLER_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the mapped handler for the best matching pattern.static String
BEST_MATCHING_PATTERN_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the best matching pattern within the handler mapping.static String
INTROSPECT_TYPE_LEVEL_MAPPING
Name of the booleanHttpServletRequest
attribute that indicates whether type-level mappings should be inspected.static String
MATRIX_VARIABLES_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains a map with URI matrix variables.static String
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the path within the handler mapping, in case of a pattern match, or the full relevant URI (typically within the DispatcherServlet's mapping) else.static String
PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the set of producible MediaTypes applicable to the mapped handler.static String
URI_TEMPLATE_VARIABLES_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the URI templates map, mapping variable names to values.
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 HandlerExecutionChain
getHandler(HttpServletRequest request)
Return a handler and any interceptors for this request.
字段详细资料
BEST_MATCHING_HANDLER_ATTRIBUTE
static final String BEST_MATCHING_HANDLER_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the mapped handler for the best matching pattern.- 从以下版本开始:
- 4.3.21
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
static final String PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the path within the handler mapping, in case of a pattern match, or the full relevant URI (typically within the DispatcherServlet's mapping) else.Note: This attribute is not required to be supported by all HandlerMapping implementations. URL-based HandlerMappings will typically support it, but handlers should not necessarily expect this request attribute to be present in all scenarios.
BEST_MATCHING_PATTERN_ATTRIBUTE
static final String BEST_MATCHING_PATTERN_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the best matching pattern within the handler mapping.Note: This attribute is not required to be supported by all HandlerMapping implementations. URL-based HandlerMappings will typically support it, but handlers should not necessarily expect this request attribute to be present in all scenarios.
INTROSPECT_TYPE_LEVEL_MAPPING
static final String INTROSPECT_TYPE_LEVEL_MAPPING
Name of the booleanHttpServletRequest
attribute that indicates whether type-level mappings should be inspected.Note: This attribute is not required to be supported by all HandlerMapping implementations.
URI_TEMPLATE_VARIABLES_ATTRIBUTE
static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the URI templates map, mapping variable names to values.Note: This attribute is not required to be supported by all HandlerMapping implementations. URL-based HandlerMappings will typically support it, but handlers should not necessarily expect this request attribute to be present in all scenarios.
MATRIX_VARIABLES_ATTRIBUTE
static final String MATRIX_VARIABLES_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains a map with URI matrix variables.Note: This attribute is not required to be supported by all HandlerMapping implementations and may also not be present depending on whether the HandlerMapping is configured to keep matrix variable content in the request URI.
PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
static final String PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the set of producible MediaTypes applicable to the mapped handler.Note: This attribute is not required to be supported by all HandlerMapping implementations. Handlers should not necessarily expect this request attribute to be present in all scenarios.
方法详细资料
getHandler
HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception
Return a handler and any interceptors for this request. The choice may be made on request URL, session state, or any factor the implementing class chooses.The returned HandlerExecutionChain contains a handler Object, rather than even a tag interface, so that handlers are not constrained in any way. For example, a HandlerAdapter could be written to allow another framework's handler objects to be used.
Returns
null
if no match was found. This is not an error. The DispatcherServlet will query all registered HandlerMapping beans to find a match, and only decide there is an error if none can find a handler.- 参数:
request
- current HTTP request- 返回:
- a HandlerExecutionChain instance containing handler object and any interceptors, or
null
if no mapping found - 抛出:
Exception
- if there is an internal error