1.3.6. View Resolution Same in Spring MVC
View resolution enables rendering to a browser with an HTML template
and a model without tying you to a specific view technology. In Spring
WebFlux, view resolution is supported through a dedicated
HandlerResultHandler that uses ViewResolver's to map a String,
representing a logical view name, to a View instance. The View is then
used to render the response.
Handling Same in Spring MVC
The HandlerResult passed into ViewResolutionResultHandler contains the
return value from the handler, and also the model that contains
attributes added during request handling. The return value is
processed as one of the following:
String, CharSequence — a logical view name to be resolved to a View
through the list of configured ViewResolver's.
void — select a default view name based on the request path minus the
leading and trailing slash, and resolve it to a View. The same also
happens when a view name was not provided, e.g. model attribute was
returned, or an async return value, e.g. Mono completed empty.
Rendering — API for view resolution scenarios; explore the options in
your IDE with code completion.
Model, Map — extra model attributes to be added to the model for the
request.
Any other — any other return value (except for simple types, as
determined by BeanUtils#isSimpleProperty) is treated as a model
attribute to be added to the model. The attribute name is derived from
the Class name, using Conventions, unless a handler method
@ModelAttribute annotation is present.
The model can contain asynchronous, reactive types (e.g. from Reactor,
RxJava). Prior to rendering, AbstractView resolves such model
attributes into concrete values and updates the model. Single-value
reactive types are resolved to a single value, or no value (if empty)
while multi-value reactive types, e.g. Flux are collected and
resolved to List.
To configure view resolution is as simple as adding a
ViewResolutionResultHandler bean to your Spring configuration. WebFlux
Config provides a dedicated configuration API for view resolution.
See View Technologies for more on the view technologies integrated
with Spring WebFlux