Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.web.servlet.mvc.annotation
Class AnnotationMethodHandlerAdapter

    java.lang.Object
      org.springframework.context.support.ApplicationObjectSupport
          org.springframework.web.context.support.WebApplicationObjectSupport
              org.springframework.web.servlet.support.WebContentGenerator
                  org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter

All Implemented Interfaces:
  ApplicationContextAware, ServletContextAware, HandlerAdapter

    public class AnnotationMethodHandlerAdapter

extends WebContentGenerator
implements HandlerAdapter

Implementation of the `HandlerAdapter` interface that maps handler methods based on HTTP paths, HTTP methods and request parameters expressed through the `RequestMapping` annotation.

Supports request parameter binding through the `RequestParam` annotation. Also supports the `ModelAttribute` annotation for exposing model attribute values to the view, as well as `InitBinder` for binder initialization methods and `SessionAttributes` for automatic session management of specific attributes.

This adapter can be customized through various bean properties. A common use case is to apply shared binder initialization logic through a custom `WebBindingInitializer`.

Since:
  2.5
Author:
  Juergen Hoeller, Arjen Poutsma
See Also:
  `setPathMatcher(org.springframework.util.PathMatcher)`, `setMethodNameResolver(org.springframework.web.servlet.mvc.multiaction.MethodNameResolver)`, `setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer)`, `setSessionAttributeStore(org.springframework.web.bind.support.SessionAttributeStore)`

Field Summary

Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator
`METHOD_GET, METHOD_HEAD, METHOD_POST`

Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
`logger`

Constructor Summary
`AnnotationMethodHandlerAdapter()`

Method Summary
`long` | `getLastModified(HttpServletRequest request, Object handler)` Same contract as for HttpServlet's `getLastModified` method.
`ModelAndView` | `handle(HttpServletRequest request, HttpServletResponse response, Object handler)` Use the given handler to handle this request.
`void` | `setAlwaysUseFullPath(boolean alwaysUseFullPath)` Set if URL lookup should always use the full path within the current servlet context.
`void` | `setMethodNameResolver(MethodNameResolver methodNameResolver)` Set the MethodNameResolver to use for resolving default handler methods (carrying an empty `@RequestMapping` annotation).
`void` | `setPathMatcher(PathMatcher pathMatcher)` Set the PathMatcher implementation to use for matching URL paths against registered URL patterns.
`void` | `setSessionAttributeStore(SessionAttributeStore sessionAttributeStore)` Specify the strategy to store session attributes with.
`void` | `setUrlDecode(boolean urlDecode)` Set if context path and request URI should be URL-decoded.
`void` | `setUrlPathHelper(UrlPathHelper urlPathHelper)` Set the UrlPathHelper to use for resolution of lookup paths.
`void` | `setWebBindingInitializer(WebBindingInitializer webBindingInitializer)` Specify a WebBindingInitializer which will apply pre-configured configuration to every DataBinder that this controller uses.
`boolean` | `supports(Object handler)` Given a handler instance, return whether or not this HandlerAdapter can support it.

Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator
`applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseExpiresHeader`

Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
`getServletContext, getTempDir, getWebApplicationContext, isContextRequired, setServletContext`

Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
`getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AnnotationMethodHandlerAdapter

    public AnnotationMethodHandlerAdapter()

Method Detail

### setAlwaysUseFullPath

    public void setAlwaysUseFullPath(boolean alwaysUseFullPath)

  Set if URL lookup should always use the full path within the current servlet context. Else, the path within the current servlet mapping is used if applicable (that is, in the case of a ".../*" servlet mapping in web.xml).

  Default is "false".

  See Also:
    `UrlPathHelper.setAlwaysUseFullPath(boolean)`

### setUrlDecode

    public void setUrlDecode(boolean urlDecode)

  Set if context path and request URI should be URL-decoded. Both are returned undecoded by the Servlet API, in contrast to the servlet path.

  Uses either the request encoding or the default encoding according to the Servlet spec (ISO-8859-1).

  See Also:
    `UrlPathHelper.setUrlDecode(boolean)`

### setUrlPathHelper

    public void setUrlPathHelper(UrlPathHelper urlPathHelper)

  Set the UrlPathHelper to use for resolution of lookup paths.

  Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and HandlerAdapters.

### setPathMatcher

    public void setPathMatcher(PathMatcher pathMatcher)

  Set the PathMatcher implementation to use for matching URL paths against registered URL patterns. Default is AntPathMatcher.

  See Also:
    `AntPathMatcher`

### setMethodNameResolver

    public void setMethodNameResolver(MethodNameResolver methodNameResolver)

  Set the MethodNameResolver to use for resolving default handler methods (carrying an empty `@RequestMapping` annotation).

  Will only kick in when the handler method cannot be resolved uniquely through the annotation metadata already.

### setWebBindingInitializer

    public void setWebBindingInitializer(WebBindingInitializer webBindingInitializer)

  Specify a WebBindingInitializer which will apply pre-configured configuration to every DataBinder that this controller uses.

### setSessionAttributeStore

    public void setSessionAttributeStore(SessionAttributeStore sessionAttributeStore)

  Specify the strategy to store session attributes with.

  Default is `DefaultSessionAttributeStore`, storing session attributes in the HttpSession, using the same attribute name as in the model.

### supports

    public boolean supports(Object handler)

  Description copied from interface: `HandlerAdapter`
  Given a handler instance, return whether or not this HandlerAdapter 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);`

  Specified by:
    `supports` in interface `HandlerAdapter`
  Parameters:
    `handler` - handler object to check
  Returns:
    whether or not this object can use the given handler

### handle

    public ModelAndView handle(HttpServletRequest request,
                               HttpServletResponse response,
                               Object handler)
                        throws Exception

  Description copied from interface: `HandlerAdapter`
  Use the given handler to handle this request. The workflow that is required may vary widely.

  Specified by:
    `handle` in interface `HandlerAdapter`
  Parameters:
    `request` - current HTTP request
    `response` - current HTTP response
    `handler` - handler to use. This object must have previously been passed to the `supports` method of this interface, which must have returned `true`.
  Returns:
    ModelAndView object with the name of the view and the required model data, or `null` if the request has been handled directly
  Throws:
    `Exception` - in case of errors

### getLastModified

    public long getLastModified(HttpServletRequest request,
                                Object handler)

  Description copied from interface: `HandlerAdapter`
  Same contract as for HttpServlet's `getLastModified` method. Can simply return -1 if there's no support in the handler class.

  Specified by:
    `getLastModified` in interface `HandlerAdapter`
  Parameters:
    `request` - current HTTP request
    `handler` - handler to use
  Returns:
    the lastModified value for the given handler
  See Also:
    `HttpServlet.getLastModified(javax.servlet.http.HttpServletRequest)`, `LastModified.getLastModified(javax.servlet.http.HttpServletRequest)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2007 The Spring Framework.