接口 HandlerAdapter
- 所有已知实现类:
AbstractHandlerMethodAdapter
,HandlerFunctionAdapter
,HttpRequestHandlerAdapter
,RequestMappingHandlerAdapter
,SimpleControllerHandlerAdapter
,SimpleServletHandlerAdapter
public interface HandlerAdapter
MVC framework SPI, allowing parameterization of the core MVC workflow.Interface that must be implemented for each handler type to handle a request. This interface is used to allow the
DispatcherServlet
to be indefinitely extensible. TheDispatcherServlet
accesses all installed handlers through this interface, meaning that it does not contain code specific to any handler type.Note that a handler can be of type
Object
. This is to enable handlers from other frameworks to be integrated with this framework without custom coding, as well as to allow for annotation-driven handler objects that do not obey any specific Java interface.This interface is not intended for application developers. It is available to handlers who want to develop their own web workflow.
Note:
HandlerAdapter
implementors may implement theOrdered
interface to be able to specify a sorting order (and thus a priority) for getting applied by theDispatcherServlet
. Non-Ordered instances get treated as lowest priority.- 作者:
- Rod Johnson, Juergen Hoeller
- 另请参阅:
SimpleControllerHandlerAdapter
,SimpleServletHandlerAdapter
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 long
getLastModified(HttpServletRequest request, Object handler)
Same contract as for HttpServlet'sgetLastModified
method.ModelAndView
handle(HttpServletRequest request, HttpServletResponse response, Object handler)
Use the given handler to handle this request.boolean
supports(Object handler)
Given a handler instance, return whether or not thisHandlerAdapter
can support it.
方法详细资料
supports
boolean supports(Object handler)
Given a handler instance, return whether or not thisHandlerAdapter
can support it. Typical HandlerAdapters will base the decision on the handler type. HandlerAdapters will usually only support one handler type each.A typical implementation:
return (handler instanceof MyHandler);
- 参数:
handler
- the handler object to check- 返回:
- whether or not this object can use the given handler
handle
@Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
Use the given handler to handle this request. The workflow that is required may vary widely.- 参数:
request
- current HTTP requestresponse
- current HTTP responsehandler
- the handler to use. This object must have previously been passed to thesupports
method of this interface, which must have returnedtrue
.- 返回:
- a ModelAndView object with the name of the view and the required model data, or
null
if the request has been handled directly - 抛出:
Exception
- in case of errors
getLastModified
long getLastModified(HttpServletRequest request, Object handler)
Same contract as for HttpServlet'sgetLastModified
method. Can simply return -1 if there's no support in the handler class.- 参数:
request
- current HTTP requesthandler
- the handler to use- 返回:
- the lastModified value for the given handler
- 另请参阅:
HttpServlet.getLastModified(javax.servlet.http.HttpServletRequest)
,LastModified.getLastModified(javax.servlet.http.HttpServletRequest)