|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2017 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | import java.lang.annotation.Retention;
|
22 | 22 | import java.lang.annotation.RetentionPolicy;
|
23 | 23 | import java.lang.annotation.Target;
|
24 |
| -import java.util.concurrent.Callable; |
25 | 24 |
|
26 | 25 | import org.springframework.core.annotation.AliasFor;
|
27 | 26 |
|
28 | 27 | /**
|
29 | 28 | * Annotation for mapping web requests onto specific handler classes and/or
|
30 | 29 | * handler methods.
|
31 | 30 | *
|
32 |
| - * <p>Handler methods which are annotated with this annotation are allowed to |
33 |
| - * have very flexible signatures. They may have parameters of the following |
34 |
| - * types, in arbitrary order (except for validation results, which need to |
35 |
| - * follow right after the corresponding command object, if desired): |
36 |
| - * <ul> |
37 |
| - * <li>Request and/or response objects from the Servlet API. |
38 |
| - * You may choose any specific request/response type, e.g. |
39 |
| - * {@link javax.servlet.ServletRequest} / {@link javax.servlet.http.HttpServletRequest}. |
40 |
| - * <li>Session object: typically {@link javax.servlet.http.HttpSession}. |
41 |
| - * An argument of this type will enforce the presence of a corresponding session. |
42 |
| - * As a consequence, such an argument will never be {@code null}. |
43 |
| - * <i>Note that session access may not be thread-safe, in particular in a |
44 |
| - * Servlet environment: Consider switching the |
45 |
| - * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#setSynchronizeOnSession |
46 |
| - * "synchronizeOnSession"} flag to "true" if multiple requests are allowed to |
47 |
| - * access a session concurrently.</i> |
48 |
| - * <li>{@link org.springframework.web.context.request.WebRequest} or |
49 |
| - * {@link org.springframework.web.context.request.NativeWebRequest}. |
50 |
| - * Allows for generic request parameter access as well as request/session |
51 |
| - * attribute access, without ties to the native Servlet API. |
52 |
| - * <li>{@link java.util.Locale} for the current request locale |
53 |
| - * (determined by the most specific locale resolver available, |
54 |
| - * i.e. the configured {@link org.springframework.web.servlet.LocaleResolver} |
55 |
| - * in a Servlet environment). |
56 |
| - * <li>{@link java.io.InputStream} / {@link java.io.Reader} for access |
57 |
| - * to the request's content. This will be the raw InputStream/Reader as |
58 |
| - * exposed by the Servlet API. |
59 |
| - * <li>{@link java.io.OutputStream} / {@link java.io.Writer} for generating |
60 |
| - * the response's content. This will be the raw OutputStream/Writer as |
61 |
| - * exposed by the Servlet API. |
62 |
| - * <li>{@link org.springframework.http.HttpMethod} for the HTTP request method</li> |
63 |
| - * <li>{@link PathVariable @PathVariable} annotated parameters |
64 |
| - * for access to URI template values (i.e. /hotels/{hotel}). Variable values will be |
65 |
| - * converted to the declared method argument type. By default, the URI template |
66 |
| - * will match against the regular expression {@code [^\.]*} (i.e. any character |
67 |
| - * other than period), but this can be changed by specifying another regular |
68 |
| - * expression, like so: /hotels/{hotel:\d+}. |
69 |
| - * Additionally, {@code @PathVariable} can be used on a |
70 |
| - * {@link java.util.Map Map<String, String>} to gain access to all |
71 |
| - * URI template variables. |
72 |
| - * <li>{@link MatrixVariable @MatrixVariable} annotated parameters |
73 |
| - * for access to name-value pairs located in URI path segments. Matrix variables |
74 |
| - * must be represented with a URI template variable. For example /hotels/{hotel} |
75 |
| - * where the incoming URL may be "/hotels/42;q=1". |
76 |
| - * Additionally, {@code @MatrixVariable} can be used on a |
77 |
| - * {@link java.util.Map Map<String, String>} to gain access to all |
78 |
| - * matrix variables in the URL or to those in a specific path variable. |
79 |
| - * <li>{@link RequestParam @RequestParam} annotated parameters for access to |
80 |
| - * specific Servlet request parameters. Parameter values will be |
81 |
| - * converted to the declared method argument type. Additionally, |
82 |
| - * {@code @RequestParam} can be used on a {@link java.util.Map Map<String, String>} or |
83 |
| - * {@link org.springframework.util.MultiValueMap MultiValueMap<String, String>} |
84 |
| - * method parameter to gain access to all request parameters. |
85 |
| - * <li>{@link RequestHeader @RequestHeader} annotated parameters for access to |
86 |
| - * specific Servlet request HTTP headers. Parameter values will be |
87 |
| - * converted to the declared method argument type. Additionally, |
88 |
| - * {@code @RequestHeader} can be used on a {@link java.util.Map Map<String, String>}, |
89 |
| - * {@link org.springframework.util.MultiValueMap MultiValueMap<String, String>}, or |
90 |
| - * {@link org.springframework.http.HttpHeaders HttpHeaders} method parameter to |
91 |
| - * gain access to all request headers. |
92 |
| - * <li>{@link RequestBody @RequestBody} annotated parameters |
93 |
| - * for access to the Servlet request HTTP contents. The request stream will be |
94 |
| - * converted to the declared method argument type using |
95 |
| - * {@linkplain org.springframework.http.converter.HttpMessageConverter message |
96 |
| - * converters}. Such parameters may optionally be annotated with {@code @Valid} |
97 |
| - * and also support access to validation results through an |
98 |
| - * {@link org.springframework.validation.Errors} argument. |
99 |
| - * Instead a {@link org.springframework.web.bind.MethodArgumentNotValidException} |
100 |
| - * exception is raised. |
101 |
| - * <li>{@link RequestPart @RequestPart} annotated parameters for access to the content |
102 |
| - * of a part of "multipart/form-data" request. The request part stream will be |
103 |
| - * converted to the declared method argument type using |
104 |
| - * {@linkplain org.springframework.http.converter.HttpMessageConverter message |
105 |
| - * converters}. Such parameters may optionally be annotated with {@code @Valid} |
106 |
| - * and support access to validation results through a |
107 |
| - * {@link org.springframework.validation.Errors} argument. |
108 |
| - * Instead a {@link org.springframework.web.bind.MethodArgumentNotValidException} |
109 |
| - * exception is raised. |
110 |
| - * <li>{@link SessionAttribute @SessionAttribute} annotated parameters for access |
111 |
| - * to existing, permanent session attributes (e.g. user authentication object) |
112 |
| - * as opposed to model attributes temporarily stored in the session as part of |
113 |
| - * a controller workflow via {@link SessionAttributes}. |
114 |
| - * <li>{@link RequestAttribute @RequestAttribute} annotated parameters for access |
115 |
| - * to request attributes. |
116 |
| - * <li>{@link org.springframework.http.HttpEntity HttpEntity<?>} parameters |
117 |
| - * for access to the Servlet request HTTP headers and contents. |
118 |
| - * The request stream will be converted to the entity body using |
119 |
| - * {@linkplain org.springframework.http.converter.HttpMessageConverter message |
120 |
| - * converters}. |
121 |
| - * <li>{@link java.util.Map} / {@link org.springframework.ui.Model} / |
122 |
| - * {@link org.springframework.ui.ModelMap} for enriching the implicit model |
123 |
| - * that will be exposed to the web view. |
124 |
| - * <li>{@link org.springframework.web.servlet.mvc.support.RedirectAttributes}, |
125 |
| - * to specify the exact set of attributes |
126 |
| - * to use in case of a redirect and also to add flash attributes (attributes |
127 |
| - * stored temporarily on the server-side to make them available to the request |
128 |
| - * after the redirect). {@code RedirectAttributes} is used instead of the |
129 |
| - * implicit model if the method returns a "redirect:" prefixed view name or |
130 |
| - * {@code RedirectView}. |
131 |
| - * <li>Command/form objects to bind parameters to: as bean properties or fields, |
132 |
| - * with customizable type conversion, depending on {@link InitBinder} methods |
133 |
| - * and/or the HandlerAdapter configuration - see the "webBindingInitializer" |
134 |
| - * property on RequestMappingHandlerMethodAdapter. |
135 |
| - * Such command objects along with their validation results will be exposed |
136 |
| - * as model attributes, by default using the non-qualified command class name |
137 |
| - * in property notation (e.g. "orderAddress" for type "mypackage.OrderAddress"). |
138 |
| - * Specify a parameter-level {@link ModelAttribute @ModelAttribute} annotation for |
139 |
| - * declaring a specific model attribute name. |
140 |
| - * <li>{@link org.springframework.validation.Errors} / |
141 |
| - * {@link org.springframework.validation.BindingResult} validation results |
142 |
| - * for a preceding command/form object (the immediate preceding argument). |
143 |
| - * <li>{@link org.springframework.web.bind.support.SessionStatus} status handle |
144 |
| - * for marking form processing as complete (triggering the cleanup of session |
145 |
| - * attributes that have been indicated by the {@link SessionAttributes @SessionAttributes} |
146 |
| - * annotation at the handler type level). |
147 |
| - * <li>{@link org.springframework.web.util.UriComponentsBuilder} |
148 |
| - * for preparing a URL relative to the current request's host, port, scheme, |
149 |
| - * context path, and the literal part of the servlet mapping. |
150 |
| - * </ul> |
151 |
| - * |
152 |
| - * <p><strong>Note:</strong> Java 8's {@code java.util.Optional} is supported |
153 |
| - * as a method parameter type with annotations that provide a {@code required} |
154 |
| - * attribute (e.g. {@code @RequestParam}, {@code @RequestHeader}, etc.). The use |
155 |
| - * of {@code java.util.Optional} in those cases is equivalent to having |
156 |
| - * {@code required=false}. |
157 |
| - * |
158 |
| - * <p>The following return types are supported for handler methods: |
159 |
| - * <ul> |
160 |
| - * <li>{@link org.springframework.web.servlet.ModelAndView} object (Spring MVC only), |
161 |
| - * providing a view, model attributes, and optionally a response status. |
162 |
| - * <li>{@link org.springframework.web.reactive.result.view.Rendering} object (Spring WebFlux only), |
163 |
| - * providing a view, model attributes, and optionally a response status. |
164 |
| - * <li>{@link org.springframework.ui.Model Model} object, with the view name implicitly |
165 |
| - * determined through a {@link org.springframework.web.servlet.RequestToViewNameTranslator} |
166 |
| - * and the model implicitly enriched with command objects and the results |
167 |
| - * of {@link ModelAttribute @ModelAttribute} annotated reference data accessor methods. |
168 |
| - * <li>{@link java.util.Map} object for exposing a model, |
169 |
| - * with the view name implicitly determined through a |
170 |
| - * {@link org.springframework.web.servlet.RequestToViewNameTranslator} |
171 |
| - * and the model implicitly enriched with command objects and the results |
172 |
| - * of {@link ModelAttribute @ModelAttribute} annotated reference data accessor methods. |
173 |
| - * <li>{@link org.springframework.web.servlet.View} object, with the |
174 |
| - * model implicitly determined through command objects and |
175 |
| - * {@link ModelAttribute @ModelAttribute} annotated reference data accessor methods. |
176 |
| - * The handler method may also programmatically enrich the model by |
177 |
| - * declaring a {@link org.springframework.ui.Model} argument (see above). |
178 |
| - * <li>{@link String} value which is interpreted as view name, |
179 |
| - * with the model implicitly determined through command objects and |
180 |
| - * {@link ModelAttribute @ModelAttribute} annotated reference data accessor methods. |
181 |
| - * The handler method may also programmatically enrich the model by |
182 |
| - * declaring a {@link org.springframework.ui.ModelMap} argument |
183 |
| - * (see above). |
184 |
| - * <li>{@link ResponseBody @ResponseBody} annotated methods |
185 |
| - * for access to the Servlet response HTTP contents. The return value will |
186 |
| - * be converted to the response stream using |
187 |
| - * {@linkplain org.springframework.http.converter.HttpMessageConverter message |
188 |
| - * converters}. |
189 |
| - * <li>{@link org.springframework.http.HttpEntity HttpEntity<?>} or |
190 |
| - * {@link org.springframework.http.ResponseEntity ResponseEntity<?>} object |
191 |
| - * to access to the Servlet response HTTP headers and contents. |
192 |
| - * The entity body will be converted to the response stream using |
193 |
| - * {@linkplain org.springframework.http.converter.HttpMessageConverter message |
194 |
| - * converters}. |
195 |
| - * <li>{@link org.springframework.http.HttpHeaders HttpHeaders} object to |
196 |
| - * return a response with no body.</li> |
197 |
| - * <li>{@link Callable} -- async computation in a Spring MVC managed thread.</li> |
198 |
| - * <li>{@link org.springframework.web.context.request.async.DeferredResult DeferredResult} -- |
199 |
| - * async result produced later from an application managed, or any thread. |
200 |
| - * <li>{@link org.springframework.util.concurrent.ListenableFuture ListenableFuture} |
201 |
| - * alternative, equivalent to {@code DeferredResult}.</li> |
202 |
| - * <li>{@link java.util.concurrent.CompletionStage CompletionStage} and |
203 |
| - * {@link java.util.concurrent.CompletableFuture CompletableFuture} -- |
204 |
| - * alternative, equivalent to {@code DeferredResult}.</li> |
205 |
| - * <li>{@link org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter} -- |
206 |
| - * {@code @ResponseBody}-style, asynchronous writing of a stream of Objects to the |
207 |
| - * response body.</li> |
208 |
| - * <li>{@link org.springframework.web.servlet.mvc.method.annotation.SseEmitter} -- |
209 |
| - * variant of {@code ResponseBodyEmitter} for a Server-Sent Events formatted stream.</li> |
210 |
| - * <li>{@link org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody} -- |
211 |
| - * async writing directly to the response body {@link java.io.OutputStream}.</li> |
212 |
| - * <li>Reactive types (e.g. Reactor {@code Flux}/{@code Mono}, RxJava 1 & 2 |
213 |
| - * {@code Observable}/{@code Single}, or others via |
214 |
| - * {@link org.springframework.core.ReactiveAdapterRegistry ReactiveAdapterRegistry}) -- |
215 |
| - * alternatives, equivalent to {@code DeferredResult} or {@code ResponseBodyEmitter} |
216 |
| - * and {@code SseEmitter} depending also on the requested media types (e.g. |
217 |
| - * "text/event-stream", "application/json+stream").</li> |
218 |
| - * <li>{@code void} if the method handles the response itself (by |
219 |
| - * writing the response content directly, declaring an argument of type |
220 |
| - * {@link javax.servlet.ServletResponse} / {@link javax.servlet.http.HttpServletResponse} |
221 |
| - * for that purpose) or if the view name is supposed to be implicitly determined |
222 |
| - * through a {@link org.springframework.web.servlet.RequestToViewNameTranslator} |
223 |
| - * (not declaring a response argument in the handler method signature). |
224 |
| - * <li>Any other return type will be considered as single model attribute |
225 |
| - * to be exposed to the view, using the attribute name specified through |
226 |
| - * {@link ModelAttribute @ModelAttribute} at the method level (or the default attribute |
227 |
| - * name based on the return type's class name otherwise). The model will be |
228 |
| - * implicitly enriched with command objects and the results of |
229 |
| - * {@link ModelAttribute @ModelAttribute} annotated reference data accessor methods. |
230 |
| - * </ul> |
| 31 | + * <p>Handler methods annotated with this annotation can have very flexible |
| 32 | + * signatures. The exact details of the supported method arguments and return |
| 33 | + * values depend on the specific |
| 34 | + * {@link org.springframework.stereotype.Controller @Controller} model supported. |
| 35 | + * Both Spring Web MVC and Spring WebFlux support this annotation with some |
| 36 | + * differences. More details are available in the Spring Framework reference. |
231 | 37 | *
|
232 | 38 | * <p><b>NOTE:</b> {@code @RequestMapping} will only be processed if an
|
233 | 39 | * an appropriate {@code HandlerMapping}-{@code HandlerAdapter} pair
|
|
256 | 62 | * @see SessionAttribute
|
257 | 63 | * @see SessionAttributes
|
258 | 64 | * @see InitBinder
|
259 |
| - * @see org.springframework.web.context.request.WebRequest |
260 | 65 | * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
|
| 66 | + * @see org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter |
261 | 67 | */
|
262 | 68 | @Target({ElementType.METHOD, ElementType.TYPE})
|
263 | 69 | @Retention(RetentionPolicy.RUNTIME)
|
|
0 commit comments