Fix cross references
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-controller-advice]]
|
||||
= Controller Advice
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-controller-advice, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-advice.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
Typically, the `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply
|
||||
within the `@Controller` class (or class hierarchy) in which they are declared. If you
|
||||
@@ -9,8 +9,8 @@ want such methods to apply more globally (across controllers), you can declare t
|
||||
class annotated with `@ControllerAdvice` or `@RestControllerAdvice`.
|
||||
|
||||
`@ControllerAdvice` is annotated with `@Component`, which means that such classes can be
|
||||
registered as Spring beans through <<core.adoc#beans-java-instantiating-container-scan,
|
||||
component scanning>>. `@RestControllerAdvice` is a composed annotation that is annotated
|
||||
registered as Spring beans through xref:core/beans/java/instantiating-container.adoc#beans-java-instantiating-container-scan[component scanning]
|
||||
. `@RestControllerAdvice` is a composed annotation that is annotated
|
||||
with both `@ControllerAdvice` and `@ResponseBody`, which essentially means
|
||||
`@ExceptionHandler` methods are rendered to the response body through message conversion
|
||||
(versus view resolution or template rendering).
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[[webflux-ann-controller-exceptions]]
|
||||
= Exceptions
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-exceptionhandler, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-exceptionhandler.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
`@Controller` and <<webflux-ann-controller-advice, @ControllerAdvice>> classes can have
|
||||
`@Controller` and xref:web/webflux/controller/ann-advice.adoc[@ControllerAdvice] classes can have
|
||||
`@ExceptionHandler` methods to handle exceptions from controller methods. The following
|
||||
example includes such a handler method:
|
||||
|
||||
@@ -49,32 +49,32 @@ as shown in the preceding example. Alternatively, the annotation declaration can
|
||||
exception types to match. We generally recommend being as specific as possible in the
|
||||
argument signature and to declare your primary root exception mappings on a
|
||||
`@ControllerAdvice` prioritized with a corresponding order.
|
||||
See <<web.adoc#mvc-ann-exceptionhandler, the MVC section>> for details.
|
||||
See xref:web/webmvc/mvc-controller/ann-exceptionhandler.adoc[the MVC section] for details.
|
||||
|
||||
NOTE: An `@ExceptionHandler` method in WebFlux supports the same method arguments and
|
||||
return values as a `@RequestMapping` method, with the exception of request body-
|
||||
and `@ModelAttribute`-related method arguments.
|
||||
|
||||
Support for `@ExceptionHandler` methods in Spring WebFlux is provided by the
|
||||
`HandlerAdapter` for `@RequestMapping` methods. See <<webflux-dispatcher-handler>>
|
||||
`HandlerAdapter` for `@RequestMapping` methods. See xref:web/webflux/dispatcher-handler.adoc[`DispatcherHandler`]
|
||||
for more detail.
|
||||
|
||||
|
||||
|
||||
[[webflux-ann-exceptionhandler-args]]
|
||||
== Method Arguments
|
||||
[.small]#<<web.adoc#mvc-ann-exceptionhandler-args, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-exceptionhandler.adoc#mvc-ann-exceptionhandler-args[See equivalent in the Servlet stack]#
|
||||
|
||||
`@ExceptionHandler` methods support the same <<webflux-ann-arguments,method arguments>>
|
||||
`@ExceptionHandler` methods support the same xref:web/webflux/controller/ann-methods/arguments.adoc[method arguments]
|
||||
as `@RequestMapping` methods, except the request body might have been consumed already.
|
||||
|
||||
|
||||
|
||||
[[webflux-ann-exceptionhandler-return-values]]
|
||||
== Return Values
|
||||
[.small]#<<web.adoc#mvc-ann-exceptionhandler-return-values, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-exceptionhandler.adoc#mvc-ann-exceptionhandler-return-values[See equivalent in the Servlet stack]#
|
||||
|
||||
`@ExceptionHandler` methods support the same <<webflux-ann-return-types,return values>>
|
||||
`@ExceptionHandler` methods support the same xref:web/webflux/controller/ann-methods/return-types.adoc[return values]
|
||||
as `@RequestMapping` methods.
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-initbinder]]
|
||||
= `DataBinder`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-initbinder, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-initbinder.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
`@Controller` or `@ControllerAdvice` classes can have `@InitBinder` methods, to
|
||||
initialize instances of `WebDataBinder`. Those, in turn, are used to:
|
||||
@@ -13,7 +13,7 @@ headers, cookies, and others) to the target type of controller method arguments.
|
||||
|
||||
`@InitBinder` methods can register controller-specific `java.beans.PropertyEditor` or
|
||||
Spring `Converter` and `Formatter` components. In addition, you can use the
|
||||
<<webflux-config-conversion, WebFlux Java configuration>> to register `Converter` and
|
||||
xref:web/webflux/config.adoc#webflux-config-conversion[WebFlux Java configuration] to register `Converter` and
|
||||
`Formatter` types in a globally shared `FormattingConversionService`.
|
||||
|
||||
`@InitBinder` methods support many of the same arguments that `@RequestMapping` methods
|
||||
@@ -100,7 +100,7 @@ controller-specific `Formatter` instances, as the following example shows:
|
||||
|
||||
[[webflux-ann-initbinder-model-design]]
|
||||
== Model Design
|
||||
[.small]#<<web.adoc#mvc-ann-initbinder-model-design, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-initbinder.adoc#mvc-ann-initbinder-model-design[See equivalent in the Servlet stack]#
|
||||
|
||||
include:../../:web-data-binding-model-design.adoc[]
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-methods]]
|
||||
= Handler Methods
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-methods, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
`@RequestMapping` handler methods have a flexible signature and can choose from a range of
|
||||
supported controller method arguments and return values.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
[[webflux-ann-arguments]]
|
||||
= Method Arguments
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-arguments, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/arguments.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
The following table shows the supported controller method arguments.
|
||||
|
||||
Reactive types (Reactor, RxJava, <<webflux-reactive-libraries, or other>>) are
|
||||
Reactive types (Reactor, RxJava, xref:web-reactive.adoc#webflux-reactive-libraries[or other]) are
|
||||
supported on arguments that require blocking I/O (for example, reading the request body) to
|
||||
be resolved. This is marked in the Description column. Reactive types are not expected
|
||||
on arguments that do not require blocking.
|
||||
@@ -44,38 +44,38 @@ and others) and is equivalent to `required=false`.
|
||||
| The time zone associated with the current request, as determined by a `LocaleContextResolver`.
|
||||
|
||||
| `@PathVariable`
|
||||
| For access to URI template variables. See <<webflux-ann-requestmapping-uri-templates>>.
|
||||
| For access to URI template variables. See xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-uri-templates[URI Patterns].
|
||||
|
||||
| `@MatrixVariable`
|
||||
| For access to name-value pairs in URI path segments. See <<webflux-ann-matrix-variables>>.
|
||||
| For access to name-value pairs in URI path segments. See xref:web/webflux/controller/ann-methods/matrix-variables.adoc[Matrix Variables].
|
||||
|
||||
| `@RequestParam`
|
||||
| For access to query parameters. Parameter values are converted to the declared method argument
|
||||
type. See <<webflux-ann-requestparam>>.
|
||||
type. See xref:web/webflux/controller/ann-methods/requestparam.adoc[`@RequestParam`].
|
||||
|
||||
Note that use of `@RequestParam` is optional -- for example, to set its attributes.
|
||||
See "`Any other argument`" later in this table.
|
||||
|
||||
| `@RequestHeader`
|
||||
| For access to request headers. Header values are converted to the declared method argument
|
||||
type. See <<webflux-ann-requestheader>>.
|
||||
type. See xref:web/webflux/controller/ann-methods/requestheader.adoc[`@RequestHeader`].
|
||||
|
||||
| `@CookieValue`
|
||||
| For access to cookies. Cookie values are converted to the declared method argument type.
|
||||
See <<webflux-ann-cookievalue>>.
|
||||
See xref:web/webflux/controller/ann-methods/cookievalue.adoc[`@CookieValue`].
|
||||
|
||||
| `@RequestBody`
|
||||
| For access to the HTTP request body. Body content is converted to the declared method
|
||||
argument type by using `HttpMessageReader` instances. Supports reactive types.
|
||||
See <<webflux-ann-requestbody>>.
|
||||
See xref:web/webflux/controller/ann-methods/requestbody.adoc[`@RequestBody`].
|
||||
|
||||
| `HttpEntity<B>`
|
||||
| For access to request headers and body. The body is converted with `HttpMessageReader` instances.
|
||||
Supports reactive types. See <<webflux-ann-httpentity>>.
|
||||
Supports reactive types. See xref:web/webflux/controller/ann-methods/httpentity.adoc[`HttpEntity`].
|
||||
|
||||
| `@RequestPart`
|
||||
| For access to a part in a `multipart/form-data` request. Supports reactive types.
|
||||
See <<webflux-multipart-forms>> and <<webflux-multipart>>.
|
||||
See xref:web/webflux/controller/ann-methods/multipart-forms.adoc[Multipart Content] and xref:web/webflux/reactive-spring.adoc#webflux-multipart[Multipart Data].
|
||||
|
||||
| `java.util.Map`, `org.springframework.ui.Model`, and `org.springframework.ui.ModelMap`.
|
||||
| For access to the model that is used in HTML controllers and is exposed to templates as
|
||||
@@ -83,8 +83,8 @@ and others) and is equivalent to `required=false`.
|
||||
|
||||
| `@ModelAttribute`
|
||||
| For access to an existing attribute in the model (instantiated if not present) with
|
||||
data binding and validation applied. See <<webflux-ann-modelattrib-method-args>> as well
|
||||
as <<webflux-ann-modelattrib-methods>> and <<webflux-ann-initbinder>>.
|
||||
data binding and validation applied. See xref:web/webflux/controller/ann-methods/modelattrib-method-args.adoc[`@ModelAttribute`] as well
|
||||
as xref:web/webflux/controller/ann-modelattrib-methods.adoc[`Model`] and xref:web/webflux/controller/ann-initbinder.adoc[`DataBinder`].
|
||||
|
||||
Note that use of `@ModelAttribute` is optional -- for example, to set its attributes.
|
||||
See "`Any other argument`" later in this table.
|
||||
@@ -97,19 +97,19 @@ and others) and is equivalent to `required=false`.
|
||||
| `SessionStatus` + class-level `@SessionAttributes`
|
||||
| For marking form processing complete, which triggers cleanup of session attributes
|
||||
declared through a class-level `@SessionAttributes` annotation.
|
||||
See <<webflux-ann-sessionattributes>> for more details.
|
||||
See xref:web/webflux/controller/ann-methods/sessionattributes.adoc[`@SessionAttributes`] for more details.
|
||||
|
||||
| `UriComponentsBuilder`
|
||||
| For preparing a URL relative to the current request's host, port, scheme, and
|
||||
context path. See <<webflux-uri-building>>.
|
||||
context path. See xref:web/webflux/uri-building.adoc[URI Links].
|
||||
|
||||
| `@SessionAttribute`
|
||||
| For access to any session attribute -- in contrast to model attributes stored in the session
|
||||
as a result of a class-level `@SessionAttributes` declaration. See
|
||||
<<webflux-ann-sessionattribute>> for more details.
|
||||
xref:web/webflux/controller/ann-methods/sessionattribute.adoc[`@SessionAttribute`] for more details.
|
||||
|
||||
| `@RequestAttribute`
|
||||
| For access to request attributes. See <<webflux-ann-requestattrib>> for more details.
|
||||
| For access to request attributes. See xref:web/webflux/controller/ann-methods/requestattrib.adoc[`@RequestAttribute`] for more details.
|
||||
|
||||
| Any other argument
|
||||
| If a method argument is not matched to any of the above, it is, by default, resolved as
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-cookievalue]]
|
||||
= `@CookieValue`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-cookievalue, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/cookievalue.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
You can use the `@CookieValue` annotation to bind the value of an HTTP cookie to a method argument
|
||||
in a controller.
|
||||
@@ -37,6 +37,6 @@ The following code sample demonstrates how to get the cookie value:
|
||||
|
||||
|
||||
Type conversion is applied automatically if the target method parameter type is not
|
||||
`String`. See <<webflux-ann-typeconversion>>.
|
||||
`String`. See xref:web/webflux/controller/ann-methods/typeconversion.adoc[Type Conversion].
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[[webflux-ann-httpentity]]
|
||||
= `HttpEntity`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-httpentity, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/httpentity.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
`HttpEntity` is more or less identical to using <<webflux-ann-requestbody>> but is based on a
|
||||
`HttpEntity` is more or less identical to using xref:web/webflux/controller/ann-methods/requestbody.adoc[`@RequestBody`] but is based on a
|
||||
container object that exposes request headers and the body. The following example uses an
|
||||
`HttpEntity`:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Spring offers support for the Jackson JSON library.
|
||||
|
||||
[[webflux-ann-jsonview]]
|
||||
== JSON Views
|
||||
[.small]#<<web.adoc#mvc-ann-jackson, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/jackson.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
Spring WebFlux provides built-in support for
|
||||
https://www.baeldung.com/jackson-json-view-annotation[Jackson's Serialization Views],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-matrix-variables]]
|
||||
= Matrix Variables
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-matrix-variables, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/matrix-variables.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
https://tools.ietf.org/html/rfc3986#section-3.3[RFC 3986] discusses name-value pairs in
|
||||
path segments. In Spring WebFlux, we refer to those as "`matrix variables`" based on an
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-modelattrib-method-args]]
|
||||
= `@ModelAttribute`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-modelattrib-method-args, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/modelattrib-method-args.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
You can use the `@ModelAttribute` annotation on a method argument to access an attribute from the
|
||||
model or have it instantiated if not present. The model attribute is also overlaid with
|
||||
@@ -27,8 +27,8 @@ converting individual query parameters and form fields. The following example bi
|
||||
|
||||
The `Pet` instance in the preceding example is resolved as follows:
|
||||
|
||||
* From the model if already added through <<webflux-ann-modelattrib-methods>>.
|
||||
* From the HTTP session through <<webflux-ann-sessionattributes>>.
|
||||
* From the model if already added through xref:web/webflux/controller/ann-modelattrib-methods.adoc[`Model`].
|
||||
* From the HTTP session through xref:web/webflux/controller/ann-methods/sessionattributes.adoc[`@SessionAttributes`].
|
||||
* From the invocation of a default constructor.
|
||||
* From the invocation of a "`primary constructor`" with arguments that match query
|
||||
parameters or form fields. Argument names are determined through JavaBeans
|
||||
@@ -38,8 +38,8 @@ After the model attribute instance is obtained, data binding is applied. The
|
||||
`WebExchangeDataBinder` class matches names of query parameters and form fields to field
|
||||
names on the target `Object`. Matching fields are populated after type conversion is applied
|
||||
where necessary. For more on data binding (and validation), see
|
||||
<<core.adoc#validation, Validation>>. For more on customizing data binding, see
|
||||
<<webflux-ann-initbinder>>.
|
||||
xref:web/webmvc/mvc-config/validation.adoc[Validation]. For more on customizing data binding, see
|
||||
xref:web/webflux/controller/ann-initbinder.adoc[`DataBinder`].
|
||||
|
||||
Data binding can result in errors. By default, a `WebExchangeBindException` is raised, but,
|
||||
to check for such errors in the controller method, you can add a `BindingResult` argument
|
||||
@@ -73,8 +73,8 @@ immediately next to the `@ModelAttribute`, as the following example shows:
|
||||
|
||||
You can automatically apply validation after data binding by adding the
|
||||
`jakarta.validation.Valid` annotation or Spring's `@Validated` annotation (see also
|
||||
<<core.adoc#validation-beanvalidation, Bean Validation>> and
|
||||
<<core.adoc#validation, Spring validation>>). The following example uses the `@Valid` annotation:
|
||||
xref:core/validation/beanvalidation.adoc[Bean Validation] and
|
||||
xref:web/webmvc/mvc-config/validation.adoc[Spring validation]). The following example uses the `@Valid` annotation:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
[[webflux-multipart-forms]]
|
||||
= Multipart Content
|
||||
|
||||
[.small]#<<web.adoc#mvc-multipart-forms, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/multipart-forms.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
As explained in <<webflux-multipart>>, `ServerWebExchange` provides access to multipart
|
||||
As explained in xref:web/webflux/reactive-spring.adoc#webflux-multipart[Multipart Data], `ServerWebExchange` provides access to multipart
|
||||
content. The best way to handle a file upload form (for example, from a browser) in a controller
|
||||
is through data binding to a <<webflux-ann-modelattrib-method-args, command object>>,
|
||||
is through data binding to a xref:web/webflux/controller/ann-methods/modelattrib-method-args.adoc[command object],
|
||||
as the following example shows:
|
||||
|
||||
--
|
||||
@@ -274,6 +274,6 @@ file upload.
|
||||
<6> The body contents must be completely consumed, relayed, or released to avoid memory leaks.
|
||||
|
||||
Received part events can also be relayed to another service by using the `WebClient`.
|
||||
See <<webflux-client-body-multipart>>.
|
||||
See xref:web/webflux-webclient/client-body.adoc#webflux-client-body-multipart[Multipart Data].
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-requestattrib]]
|
||||
= `@RequestAttribute`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-requestattrib, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/requestattrib.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
Similarly to `@SessionAttribute`, you can use the `@RequestAttribute` annotation to
|
||||
access pre-existing request attributes created earlier (for example, by a `WebFilter`),
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
[[webflux-ann-requestbody]]
|
||||
= `@RequestBody`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-requestbody, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/requestbody.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
You can use the `@RequestBody` annotation to have the request body read and deserialized into an
|
||||
`Object` through an <<webflux-codecs,HttpMessageReader>>.
|
||||
`Object` through an xref:web/webflux/reactive-spring.adoc#webflux-codecs[HttpMessageReader].
|
||||
The following example uses a `@RequestBody` argument:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
@@ -45,7 +45,7 @@ and fully non-blocking reading and (client-to-server) streaming.
|
||||
}
|
||||
----
|
||||
|
||||
You can use the <<webflux-config-message-codecs>> option of the <<webflux-config>> to
|
||||
You can use the xref:web/webflux/config.adoc#webflux-config-message-codecs[HTTP message codecs] option of the xref:web/webflux/dispatcher-handler.adoc#webflux-framework-config[WebFlux Config] to
|
||||
configure or customize message readers.
|
||||
|
||||
You can use `@RequestBody` in combination with `jakarta.validation.Valid` or Spring's
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-requestheader]]
|
||||
= `@RequestHeader`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-requestheader, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/requestheader.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
You can use the `@RequestHeader` annotation to bind a request header to a method argument in a
|
||||
controller.
|
||||
@@ -48,7 +48,7 @@ The following example gets the value of the `Accept-Encoding` and `Keep-Alive` h
|
||||
<2> Get the value of the `Keep-Alive` header.
|
||||
|
||||
Type conversion is applied automatically if the target method parameter type is not
|
||||
`String`. See <<webflux-ann-typeconversion>>.
|
||||
`String`. See xref:web/webflux/controller/ann-methods/typeconversion.adoc[Type Conversion].
|
||||
|
||||
When a `@RequestHeader` annotation is used on a `Map<String, String>`,
|
||||
`MultiValueMap<String, String>`, or `HttpHeaders` argument, the map is populated
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-requestparam]]
|
||||
= `@RequestParam`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-requestparam, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/requestparam.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
You can use the `@RequestParam` annotation to bind query parameters to a method argument in a
|
||||
controller. The following code snippet shows the usage:
|
||||
@@ -54,7 +54,7 @@ TIP: The Servlet API "`request parameter`" concept conflates query parameters, f
|
||||
data, and multiparts into one. However, in WebFlux, each is accessed individually through
|
||||
`ServerWebExchange`. While `@RequestParam` binds to query parameters only, you can use
|
||||
data binding to apply query parameters, form data, and multiparts to a
|
||||
<<webflux-ann-modelattrib-method-args, command object>>.
|
||||
xref:web/webflux/controller/ann-methods/modelattrib-method-args.adoc[command object].
|
||||
|
||||
Method parameters that use the `@RequestParam` annotation are required by default, but
|
||||
you can specify that a method parameter is optional by setting the required flag of a `@RequestParam`
|
||||
@@ -62,7 +62,7 @@ to `false` or by declaring the argument with a `java.util.Optional`
|
||||
wrapper.
|
||||
|
||||
Type conversion is applied automatically if the target method parameter type is not
|
||||
`String`. See <<webflux-ann-typeconversion>>.
|
||||
`String`. See xref:web/webflux/controller/ann-methods/typeconversion.adoc[Type Conversion].
|
||||
|
||||
When a `@RequestParam` annotation is declared on a `Map<String, String>` or
|
||||
`MultiValueMap<String, String>` argument, the map is populated with all query parameters.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
[[webflux-ann-responsebody]]
|
||||
= `@ResponseBody`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-responsebody, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/responsebody.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
You can use the `@ResponseBody` annotation on a method to have the return serialized
|
||||
to the response body through an <<webflux-codecs, HttpMessageWriter>>. The following
|
||||
to the response body through an xref:web/webflux/reactive-spring.adoc#webflux-codecs[HttpMessageWriter]. The following
|
||||
example shows how to do so:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
@@ -32,13 +32,13 @@ than a meta-annotation marked with `@Controller` and `@ResponseBody`.
|
||||
|
||||
`@ResponseBody` supports reactive types, which means you can return Reactor or RxJava
|
||||
types and have the asynchronous values they produce rendered to the response.
|
||||
For additional details, see <<webflux-codecs-streaming>> and
|
||||
<<webflux-codecs-jackson,JSON rendering>>.
|
||||
For additional details, see xref:web/webflux/reactive-spring.adoc#webflux-codecs-streaming[Streaming] and
|
||||
xref:web/webflux/reactive-spring.adoc#webflux-codecs-jackson[JSON rendering].
|
||||
|
||||
You can combine `@ResponseBody` methods with JSON serialization views.
|
||||
See <<webflux-ann-jackson>> for details.
|
||||
See xref:web/webflux/controller/ann-methods/jackson.adoc[Jackson JSON] for details.
|
||||
|
||||
You can use the <<webflux-config-message-codecs>> option of the <<webflux-config>> to
|
||||
You can use the xref:web/webflux/config.adoc#webflux-config-message-codecs[HTTP message codecs] option of the xref:web/webflux/dispatcher-handler.adoc#webflux-framework-config[WebFlux Config] to
|
||||
configure or customize message writing.
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[[webflux-ann-responseentity]]
|
||||
= `ResponseEntity`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-responseentity, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/responseentity.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
`ResponseEntity` is like <<webflux-ann-responsebody>> but with status and headers. For example:
|
||||
`ResponseEntity` is like xref:web/webflux/controller/ann-methods/responsebody.adoc[`@ResponseBody`] but with status and headers. For example:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
@@ -26,7 +26,7 @@
|
||||
}
|
||||
----
|
||||
|
||||
WebFlux supports using a single value <<webflux-reactive-libraries, reactive type>> to
|
||||
WebFlux supports using a single value xref:web-reactive.adoc#webflux-reactive-libraries[reactive type] to
|
||||
produce the `ResponseEntity` asynchronously, and/or single and multi-value reactive types
|
||||
for the body. This allows a variety of async responses with `ResponseEntity` as follows:
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
[[webflux-ann-return-types]]
|
||||
= Return Values
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-return-types, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/return-types.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
The following table shows the supported controller method return values. Note that reactive
|
||||
types from libraries such as Reactor, RxJava, <<webflux-reactive-libraries, or other>> are
|
||||
types from libraries such as Reactor, RxJava, xref:web-reactive.adoc#webflux-reactive-libraries[or other] are
|
||||
generally supported for all return values.
|
||||
|
||||
[cols="1,2", options="header"]
|
||||
@@ -13,35 +13,35 @@ generally supported for all return values.
|
||||
|
||||
| `@ResponseBody`
|
||||
| The return value is encoded through `HttpMessageWriter` instances and written to the response.
|
||||
See <<webflux-ann-responsebody>>.
|
||||
See xref:web/webflux/controller/ann-methods/responsebody.adoc[`@ResponseBody`].
|
||||
|
||||
| `HttpEntity<B>`, `ResponseEntity<B>`
|
||||
| The return value specifies the full response, including HTTP headers, and the body is encoded
|
||||
through `HttpMessageWriter` instances and written to the response.
|
||||
See <<webflux-ann-responseentity>>.
|
||||
See xref:web/webflux/controller/ann-methods/responseentity.adoc[`ResponseEntity`].
|
||||
|
||||
| `HttpHeaders`
|
||||
| For returning a response with headers and no body.
|
||||
|
||||
| `ErrorResponse`
|
||||
| To render an RFC 7807 error response with details in the body,
|
||||
see <<webflux-ann-rest-exceptions>>
|
||||
see xref:web/webflux/ann-rest-exceptions.adoc[Error Responses]
|
||||
|
||||
| `ProblemDetail`
|
||||
| To render an RFC 7807 error response with details in the body,
|
||||
see <<webflux-ann-rest-exceptions>>
|
||||
see xref:web/webflux/ann-rest-exceptions.adoc[Error Responses]
|
||||
|
||||
| `String`
|
||||
| A view name to be resolved with `ViewResolver` instances and used together with the implicit
|
||||
model -- determined through command objects and `@ModelAttribute` methods. The handler
|
||||
method can also programmatically enrich the model by declaring a `Model` argument
|
||||
(described <<webflux-viewresolution-handling, earlier>>).
|
||||
(described xref:web/webflux/dispatcher-handler.adoc#webflux-viewresolution-handling[earlier]).
|
||||
|
||||
| `View`
|
||||
| A `View` instance to use for rendering together with the implicit model -- determined
|
||||
through command objects and `@ModelAttribute` methods. The handler method can also
|
||||
programmatically enrich the model by declaring a `Model` argument
|
||||
(described <<webflux-viewresolution-handling, earlier>>).
|
||||
(described xref:web/webflux/dispatcher-handler.adoc#webflux-viewresolution-handling[earlier]).
|
||||
|
||||
| `java.util.Map`, `org.springframework.ui.Model`
|
||||
| Attributes to be added to the implicit model, with the view name implicitly determined
|
||||
@@ -62,7 +62,7 @@ generally supported for all return values.
|
||||
value) is considered to have fully handled the response if it also has a `ServerHttpResponse`,
|
||||
a `ServerWebExchange` argument, or an `@ResponseStatus` annotation. The same is also true
|
||||
if the controller has made a positive ETag or `lastModified` timestamp check.
|
||||
See <<webflux-caching-etag-lastmodified>> for details.
|
||||
See xref:web/webflux/caching.adoc#webflux-caching-etag-lastmodified[Controllers] for details.
|
||||
|
||||
If none of the above is true, a `void` return type can also indicate "`no response body`" for
|
||||
REST controllers or default view name selection for HTML controllers.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-sessionattribute]]
|
||||
= `@SessionAttribute`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-sessionattribute, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/sessionattribute.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
If you need access to pre-existing session attributes that are managed globally
|
||||
(that is, outside the controller -- for example, by a filter) and may or may not be present,
|
||||
@@ -32,6 +32,6 @@ For use cases that require adding or removing session attributes, consider injec
|
||||
|
||||
For temporary storage of model attributes in the session as part of a controller
|
||||
workflow, consider using `SessionAttributes`, as described in
|
||||
<<webflux-ann-sessionattributes>>.
|
||||
xref:web/webflux/controller/ann-methods/sessionattributes.adoc[`@SessionAttributes`].
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-sessionattributes]]
|
||||
= `@SessionAttributes`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-sessionattributes, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/sessionattributes.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
`@SessionAttributes` is used to store model attributes in the `WebSession` between
|
||||
requests. It is a type-level annotation that declares session attributes used by a
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-typeconversion]]
|
||||
= Type Conversion
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-typeconversion, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-methods/typeconversion.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
Some annotated controller method arguments that represent String-based request input (for example,
|
||||
`@RequestParam`, `@RequestHeader`, `@PathVariable`, `@MatrixVariable`, and `@CookieValue`)
|
||||
@@ -9,8 +9,8 @@ can require type conversion if the argument is declared as something other than
|
||||
|
||||
For such cases, type conversion is automatically applied based on the configured converters.
|
||||
By default, simple types (such as `int`, `long`, `Date`, and others) are supported. Type conversion
|
||||
can be customized through a `WebDataBinder` (see <<webflux-ann-initbinder>>) or by registering
|
||||
`Formatters` with the `FormattingConversionService` (see <<core.adoc#format, Spring Field Formatting>>).
|
||||
can be customized through a `WebDataBinder` (see xref:web/webflux/controller/ann-initbinder.adoc[`DataBinder`]) or by registering
|
||||
`Formatters` with the `FormattingConversionService` (see xref:core/validation/format.adoc[Spring Field Formatting]).
|
||||
|
||||
A practical issue in type conversion is the treatment of an empty String source value.
|
||||
Such a value is treated as missing if it becomes `null` as a result of type conversion.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
[[webflux-ann-modelattrib-methods]]
|
||||
= `Model`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-modelattrib-methods, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-modelattrib-methods.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
You can use the `@ModelAttribute` annotation:
|
||||
|
||||
* On a <<webflux-ann-modelattrib-method-args, method argument>> in `@RequestMapping` methods
|
||||
* On a xref:web/webflux/controller/ann-methods/modelattrib-method-args.adoc[method argument] in `@RequestMapping` methods
|
||||
to create or access an Object from the model and to bind it to the request through a
|
||||
`WebDataBinder`.
|
||||
* As a method-level annotation in `@Controller` or `@ControllerAdvice` classes, helping
|
||||
@@ -16,7 +16,7 @@ This section discusses `@ModelAttribute` methods, or the second item from the pr
|
||||
A controller can have any number of `@ModelAttribute` methods. All such methods are
|
||||
invoked before `@RequestMapping` methods in the same controller. A `@ModelAttribute`
|
||||
method can also be shared across controllers through `@ControllerAdvice`. See the section on
|
||||
<<webflux-ann-controller-advice>> for more details.
|
||||
xref:web/webflux/controller/ann-advice.adoc[Controller Advice] for more details.
|
||||
|
||||
`@ModelAttribute` methods have flexible method signatures. They support many of the same
|
||||
arguments as `@RequestMapping` methods (except for `@ModelAttribute` itself and anything
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-requestmapping]]
|
||||
= Request Mapping
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
The `@RequestMapping` annotation is used to map requests to controllers methods. It has
|
||||
various attributes to match by URL, HTTP method, request parameters, headers, and media
|
||||
@@ -16,7 +16,7 @@ There are also HTTP method specific shortcut variants of `@RequestMapping`:
|
||||
* `@DeleteMapping`
|
||||
* `@PatchMapping`
|
||||
|
||||
The preceding annotations are <<webflux-ann-requestmapping-composed>> that are provided
|
||||
The preceding annotations are xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-composed[Custom Annotations] that are provided
|
||||
because, arguably, most controller methods should be mapped to a specific HTTP method versus
|
||||
using `@RequestMapping`, which, by default, matches to all HTTP methods. At the same time, a
|
||||
`@RequestMapping` is still needed at the class level to express shared mappings.
|
||||
@@ -65,7 +65,7 @@ The following example uses type and method level mappings:
|
||||
|
||||
[[webflux-ann-requestmapping-uri-templates]]
|
||||
== URI Patterns
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping-uri-templates, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-uri-templates[See equivalent in the Servlet stack]#
|
||||
|
||||
You can map requests by using glob patterns and wildcards:
|
||||
|
||||
@@ -164,7 +164,7 @@ You can declare URI variables at the class and method levels, as the following e
|
||||
URI variables are automatically converted to the appropriate type or a `TypeMismatchException`
|
||||
is raised. Simple types (`int`, `long`, `Date`, and so on) are supported by default and you can
|
||||
register support for any other data type.
|
||||
See <<webflux-ann-typeconversion>> and <<webflux-ann-initbinder>>.
|
||||
See xref:web/webflux/controller/ann-methods/typeconversion.adoc[Type Conversion] and xref:web/webflux/controller/ann-initbinder.adoc[`DataBinder`].
|
||||
|
||||
URI variables can be named explicitly (for example, `@PathVariable("customId")`), but you can
|
||||
leave that detail out if the names are the same and you compile your code with the `-parameters`
|
||||
@@ -214,7 +214,7 @@ explicit, and less vulnerable to URL path based exploits.
|
||||
|
||||
[[webflux-ann-requestmapping-pattern-comparison]]
|
||||
== Pattern Comparison
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping-pattern-comparison, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-pattern-comparison[See equivalent in the Servlet stack]#
|
||||
|
||||
When multiple patterns match a URL, they must be compared to find the best match. This is done
|
||||
with `PathPattern.SPECIFICITY_COMPARATOR`, which looks for patterns that are more specific.
|
||||
@@ -229,7 +229,7 @@ sorted last instead. If two patterns are both catch-all, the longer is chosen.
|
||||
|
||||
[[webflux-ann-requestmapping-consumes]]
|
||||
== Consumable Media Types
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping-consumes, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-consumes[See equivalent in the Servlet stack]#
|
||||
|
||||
You can narrow the request mapping based on the `Content-Type` of the request,
|
||||
as the following example shows:
|
||||
@@ -264,7 +264,7 @@ TIP: `MediaType` provides constants for commonly used media types -- for example
|
||||
|
||||
[[webflux-ann-requestmapping-produces]]
|
||||
== Producible Media Types
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping-produces, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-produces[See equivalent in the Servlet stack]#
|
||||
|
||||
You can narrow the request mapping based on the `Accept` request header and the list of
|
||||
content types that a controller method produces, as the following example shows:
|
||||
@@ -301,7 +301,7 @@ TIP: `MediaType` provides constants for commonly used media types -- e.g.
|
||||
|
||||
[[webflux-ann-requestmapping-params-and-headers]]
|
||||
== Parameters and Headers
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping-params-and-headers, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-params-and-headers[See equivalent in the Servlet stack]#
|
||||
|
||||
You can narrow request mappings based on query parameter conditions. You can test for the
|
||||
presence of a query parameter (`myParam`), for its absence (`!myParam`), or for a
|
||||
@@ -353,7 +353,7 @@ You can also use the same with request header conditions, as the following examp
|
||||
|
||||
[[webflux-ann-requestmapping-head-options]]
|
||||
== HTTP HEAD, OPTIONS
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping-head-options, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-head-options[See equivalent in the Servlet stack]#
|
||||
|
||||
`@GetMapping` and `@RequestMapping(method=HttpMethod.GET)` support HTTP HEAD
|
||||
transparently for request mapping purposes. Controller methods need not change.
|
||||
@@ -374,9 +374,9 @@ is not necessary in the common case.
|
||||
|
||||
[[webflux-ann-requestmapping-composed]]
|
||||
== Custom Annotations
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping-composed, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-composed[See equivalent in the Servlet stack]#
|
||||
|
||||
Spring WebFlux supports the use of <<core.adoc#beans-meta-annotations, composed annotations>>
|
||||
Spring WebFlux supports the use of xref:core/beans/classpath-scanning.adoc#beans-meta-annotations[composed annotations]
|
||||
for request mapping. Those are annotations that are themselves meta-annotated with
|
||||
`@RequestMapping` and composed to redeclare a subset (or all) of the `@RequestMapping`
|
||||
attributes with a narrower, more specific purpose.
|
||||
@@ -395,7 +395,7 @@ you can check the custom attribute and return your own `RequestCondition`.
|
||||
|
||||
[[webflux-ann-requestmapping-registration]]
|
||||
== Explicit Registrations
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping-registration, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-registration[See equivalent in the Servlet stack]#
|
||||
|
||||
You can programmatically register Handler methods, which can be used for dynamic
|
||||
registrations or for advanced cases, such as different instances of the same handler
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[[webflux-ann-controller]]
|
||||
= `@Controller`
|
||||
|
||||
[.small]#<<web.adoc#mvc-ann-controller, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann.adoc[See equivalent in the Servlet stack]#
|
||||
|
||||
You can define controller beans by using a standard Spring bean definition.
|
||||
The `@Controller` stereotype allows for auto-detection and is aligned with Spring general support
|
||||
@@ -36,7 +36,7 @@ your Java configuration, as the following example shows:
|
||||
----
|
||||
<1> Scan the `org.example.web` package.
|
||||
|
||||
`@RestController` is a <<core.adoc#beans-meta-annotations, composed annotation>> that is
|
||||
`@RestController` is a xref:core/beans/classpath-scanning.adoc#beans-meta-annotations[composed annotation] that is
|
||||
itself meta-annotated with `@Controller` and `@ResponseBody`, indicating a controller whose
|
||||
every method inherits the type-level `@ResponseBody` annotation and, therefore, writes
|
||||
directly to the response body versus view resolution and rendering with an HTML template.
|
||||
@@ -45,7 +45,7 @@ directly to the response body versus view resolution and rendering with an HTML
|
||||
|
||||
[[webflux-ann-requestmapping-proxying]]
|
||||
== AOP Proxies
|
||||
[.small]#<<web.adoc#mvc-ann-requestmapping-proxying, See equivalent in the Servlet stack>>#
|
||||
[.small]#xref:web/webmvc/mvc-controller/ann.adoc#mvc-ann-requestmapping-proxying[See equivalent in the Servlet stack]#
|
||||
|
||||
In some cases, you may need to decorate a controller with an AOP proxy at runtime.
|
||||
One example is if you choose to have `@Transactional` annotations directly on the
|
||||
|
||||
Reference in New Issue
Block a user