Method Arguments

The following table shows the supported controller method arguments.spring-doc.cn

Reactive types (Reactor, RxJava, 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.spring-doc.cn

JDK 1.8’s java.util.Optional is supported as a method argument in combination with annotations that have a required attribute (for example, @RequestParam, @RequestHeader, and others) and is equivalent to required=false.spring-doc.cn

Controller method argument Description

ServerWebExchangespring-doc.cn

Access to the full ServerWebExchange — container for the HTTP request and response, request and session attributes, checkNotModified methods, and others.spring-doc.cn

ServerHttpRequest, ServerHttpResponsespring-doc.cn

Access to the HTTP request or response.spring-doc.cn

WebSessionspring-doc.cn

Access to the session. This does not force the start of a new session unless attributes are added. Supports reactive types.spring-doc.cn

java.security.Principalspring-doc.cn

The currently authenticated user — possibly a specific Principal implementation class if known. Supports reactive types.spring-doc.cn

org.springframework.http.HttpMethodspring-doc.cn

The HTTP method of the request.spring-doc.cn

java.util.Localespring-doc.cn

The current request locale, determined by the most specific LocaleResolver available — in effect, the configured LocaleResolver/LocaleContextResolver.spring-doc.cn

java.util.TimeZone + java.time.ZoneIdspring-doc.cn

The time zone associated with the current request, as determined by a LocaleContextResolver.spring-doc.cn

@PathVariablespring-doc.cn

For access to URI template variables. See URI Patterns.spring-doc.cn

@MatrixVariablespring-doc.cn

For access to name-value pairs in URI path segments. See Matrix Variables.spring-doc.cn

@RequestParamspring-doc.cn

For access to query parameters. Parameter values are converted to the declared method argument type. See @RequestParam.spring-doc.cn

Note that use of @RequestParam is optional — for example, to set its attributes. See “Any other argument” later in this table.spring-doc.cn

@RequestHeaderspring-doc.cn

For access to request headers. Header values are converted to the declared method argument type. See @RequestHeader.spring-doc.cn

@CookieValuespring-doc.cn

For access to cookies. Cookie values are converted to the declared method argument type. See @CookieValue.spring-doc.cn

@RequestBodyspring-doc.cn

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 @RequestBody.spring-doc.cn

HttpEntity<B>spring-doc.cn

For access to request headers and body. The body is converted with HttpMessageReader instances. Supports reactive types. See HttpEntity.spring-doc.cn

@RequestPartspring-doc.cn

For access to a part in a multipart/form-data request. Supports reactive types. See Multipart Content and Multipart Data.spring-doc.cn

java.util.Map or org.springframework.ui.Modelspring-doc.cn

For access to the model that is used in HTML controllers and is exposed to templates as part of view rendering.spring-doc.cn

@ModelAttributespring-doc.cn

For access to an existing attribute in the model (instantiated if not present) with data binding and validation applied. See @ModelAttribute as well as Model and DataBinder.spring-doc.cn

Note that use of @ModelAttribute is optional — for example, to set its attributes. See “Any other argument” later in this table.spring-doc.cn

Errors or BindingResultspring-doc.cn

For access to errors from validation and data binding for a command object, i.e. a @ModelAttribute argument. An Errors or BindingResult argument must be declared immediately after the validated method argument.spring-doc.cn

SessionStatus + class-level @SessionAttributesspring-doc.cn

For marking form processing complete, which triggers cleanup of session attributes declared through a class-level @SessionAttributes annotation. See @SessionAttributes for more details.spring-doc.cn

UriComponentsBuilderspring-doc.cn

For preparing a URL relative to the current request’s host, port, scheme, and context path. See URI Links.spring-doc.cn

@SessionAttributespring-doc.cn

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 @SessionAttribute for more details.spring-doc.cn

@RequestAttributespring-doc.cn

For access to request attributes. See @RequestAttribute for more details.spring-doc.cn

Any other argumentspring-doc.cn

If a method argument is not matched to any of the above, it is, by default, resolved as a @RequestParam if it is a simple type, as determined by BeanUtils#isSimpleProperty, or as a @ModelAttribute, otherwise.spring-doc.cn