The Spring Framework

org.springframework.web.bind.annotation
Annotation Type RequestMapping


@Target(value={METHOD,TYPE})
@Retention(value=RUNTIME)
@Documented
public @interface RequestMapping

Annotation for mapping web requests onto specific handler classes and/or handler methods. Provides consistent style between Servlet and Portlet environments, with the semantics adapting to the concrete environment.

NOTE: Method-level mappings are only allowed to narrow the mapping expressed at the class level (if any). HTTP paths / portlet modes need to uniquely map onto specific handler beans, with any given path / mode only allowed to be mapped onto one specific handler bean (not spread across multiple handler beans). It is strongly recommended to co-locate related handler methods into the same bean.

Handler methods which are annotated with this annotation are allowed to have very flexible signatures. They may have arguments of the following types, in arbitrary order (except for validation results, which need to follow right after the corresponding command object, if desired):

The following return types are supported for handler methods:

NOTE: @RequestMapping will only be processed if a corresponding HandlerMapping (for type level annotations) and/or HandlerAdapter (for method level annotations) is present in the dispatcher. This is the case by default in both DispatcherServlet and DispatcherPortlet. However, if you are defining custom HandlerMappings or HandlerAdapters, then you need to make sure that a corresponding custom DefaultAnnotationHandlerMapping and/or AnnotationMethodHandlerAdapter is defined as well - provided that you intend to use @RequestMapping.

Since:
2.5
Author:
Juergen Hoeller, Arjen Poutsma, Sam Brannen
See Also:
RequestParam, ModelAttribute, SessionAttributes, InitBinder, WebRequest, DefaultAnnotationHandlerMapping, AnnotationMethodHandlerAdapter, DefaultAnnotationHandlerMapping, AnnotationMethodHandlerAdapter

Optional Element Summary
 RequestMethod[] method
          The HTTP request methods to map to, narrowing the primary mapping: GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE.
 String[] params
          The parameters of the mapped request, narrowing the primary mapping.
 String[] value
          The primary mapping expressed by this annotation.
 

value

public abstract String[] value
The primary mapping expressed by this annotation.

In a Servlet environment: the path mapping URLs (e.g. "/myPath.do")

In a Portlet environment: the mapped portlet modes (e.g. "EDIT")

Supported at the type level as well as at the method level! When used at the type level, all method level mappings inherit this primary mapping, narrowing it for a specific handler method.

Default:
{}

method

public abstract RequestMethod[] method
The HTTP request methods to map to, narrowing the primary mapping: GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE.

Only supported at the handler method level in Servlet environments!

Default:
{}

params

public abstract String[] params
The parameters of the mapped request, narrowing the primary mapping.

Same format for any environment: a sequence of "myParam=myValue" style expressions, with a request only mapped if each such parameter is found to have the given value. "myParam" style expressions are also supported, with such parameters having to be present in the request (allowed to have any value).

Only supported at the handler method level!

Default:
{}

The Spring Framework

Copyright © 2002-2007 The Spring Framework.