This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Framework 6.1.12! |
Return Values
The following table shows the supported controller method return values. Note that reactive types from libraries such as Reactor, RxJava, or other are generally supported for all return values.
For return types like Flux
, when multiple values are expected, elements are streamed as they come
and are not buffered. This is the default behavior, as keeping a potentially large amount of elements in memory
is not efficient. If the media type implies an infinite stream (for example,
application/json+stream
), values are written and flushed individually. Otherwise,
values are written individually and the flushing happens separately.
If an error happens while an element is encoded to JSON, the response might have been written to and committed already
and it is impossible at that point to render a proper error response.
In some cases, applications can choose to trade memory efficiency for better handling such errors by buffering elements and encoding them all at once.
Controllers can then return a Flux<List<B>> ; Reactor provides a dedicated operator for that, Flux#collectList() .
|
Controller method return value | Description |
---|---|
|
The return value is encoded through |
|
The return value specifies the full response, including HTTP headers, and the body is encoded
through |
|
For returning a response with headers and no body. |
|
To render an RFC 9457 error response with details in the body, see Error Responses |
|
To render an RFC 9457 error response with details in the body, see Error Responses |
|
A view name to be resolved with |
|
A |
|
Attributes to be added to the implicit model, with the view name implicitly determined based on the request path. |
|
An attribute to be added to the model, with the view name implicitly determined based on the request path. Note that |
|
An API for model and view rendering scenarios. |
|
For rendering one or more fragments each with its own view and model. See HTML Fragments for more details. |
|
A method with a If none of the above is true, a |
|
Emit server-sent events. The |
Other return values |
If a return value remains unresolved in any other way, it is treated as a model attribute, unless it is a simple type as determined by BeanUtils#isSimpleProperty, in which case it remains unresolved. |