程序包 cn.taketoday.web

接口 HandlerMapping

所有已知实现类:
AbstractDetectingUrlHandlerMapping, AbstractHandlerMapping, AbstractHandlerMethodMapping, AbstractUrlHandlerMapping, BeanNameUrlHandlerMapping, HandlerRegistries, RequestMappingHandlerMapping, RequestMappingInfoHandlerMapping, RouterFunctionMapping, SimpleUrlHandlerMapping
函数接口:
这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。

@FunctionalInterface 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 and RequestMappingHandlerMapping 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 some HandlerInterceptor instances. The DispatcherHandler will first call each HandlerInterceptor's preHandle method in the given order, finally invoking the handler itself if all preHandle methods have returned true.

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 DispatcherHandler. Non-Ordered instances get treated as lowest priority.

作者:
Rod Johnson, Juergen Hoeller, TODAY 2019-12-08 23:06
另请参阅:
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final String
    Well-known name for the HandlerMapping object in the bean factory for this namespace.
  • 方法概要

    修饰符和类型
    方法
    说明
    find(cn.taketoday.context.ApplicationContext context)
     
    find(cn.taketoday.context.ApplicationContext context, boolean detectAllHandlerMapping)
     
    Return a handler and any interceptors for this request.
  • 字段详细资料

  • 方法详细资料

    • getHandler

      @Nullable Object getHandler(RequestContext 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 request context
      返回:
      a fgA instance containing handler object and any interceptors, or null if no mapping found
      抛出:
      Exception - if there is an internal error
    • find

      static HandlerMapping find(cn.taketoday.context.ApplicationContext context)
    • find

      static HandlerMapping find(cn.taketoday.context.ApplicationContext context, boolean detectAllHandlerMapping)