Top Description Fields Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

public Class ModelAndViewResolverMethodReturnValueHandler

extends Object
implements HandlerMethodReturnValueHandler
Class Inheritance
All Implemented Interfaces
org.springframework.web.method.support.HandlerMethodReturnValueHandler
Imports
java.lang.reflect.Method, java.util.List, org.springframework.core.MethodParameter, org.springframework.lang.Nullable, org.springframework.ui.ExtendedModelMap, org.springframework.util.Assert, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.method.annotation.ModelAttributeMethodProcessor, org.springframework.web.method.support.HandlerMethodReturnValueHandler, .ModelAndViewContainer, org.springframework.web.servlet.ModelAndView, org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver

This return value handler is intended to be ordered after all others as it attempts to handle _any_ return value type (i.e. returns true for all return types).

The return value is handled either with a ModelAndViewResolver or otherwise by regarding it as a model attribute if it is a non-simple type. If neither of these succeeds (essentially simple type other than String), UnsupportedOperationException is raised.

Note

This class is primarily needed to support ModelAndViewResolver, which unfortunately cannot be properly adapted to the HandlerMethodReturnValueHandler contract since the HandlerMethodReturnValueHandler#supportsReturnType method cannot be implemented. Hence ModelAndViewResolvers are limited to always being invoked at the end after all other return value handlers have been given a chance. It is recommended to re-implement a ModelAndViewResolver as HandlerMethodReturnValueHandler, which also provides better access to the return type and method information.

Author
Rossen Stoyanchev
Since
3.1

Field Summary

Modifier and TypeField and Description
private final List<ModelAndViewResolver>
private final ModelAttributeMethodProcessor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
handleReturnValue(Object
the value returned from the handler method
returnValue
,
MethodParameter
the type of the return value. This type must have previously been passed to supportsReturnType which must have returned true.
returnType
,
ModelAndViewContainer
the ModelAndViewContainer for the current request
mavContainer
,
NativeWebRequest
the current request
webRequest
)

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.handleReturnValue.

Handle the given return value by adding attributes to the model and setting a view or setting the ModelAndViewContainer#setRequestHandled flag to true to indicate the response has been handled directly.

public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mavResolversback to summary
private final List<ModelAndViewResolver> mavResolvers
Annotations
@Nullable
modelAttributeProcessorback to summary
private final ModelAttributeMethodProcessor modelAttributeProcessor

Constructor Detail

ModelAndViewResolverMethodReturnValueHandlerback to summary
public ModelAndViewResolverMethodReturnValueHandler(List<ModelAndViewResolver> mavResolvers)

Create a new instance.

Method Detail

handleReturnValueback to summary
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.handleReturnValue.

Doc from org.springframework.web.method.support.HandlerMethodReturnValueHandler.handleReturnValue.

Handle the given return value by adding attributes to the model and setting a view or setting the ModelAndViewContainer#setRequestHandled flag to true to indicate the response has been handled directly.

Parameters
returnValue:Object

the value returned from the handler method

returnType:MethodParameter

the type of the return value. This type must have previously been passed to supportsReturnType which must have returned true.

mavContainer:ModelAndViewContainer

the ModelAndViewContainer for the current request

webRequest:NativeWebRequest

the current request

Annotations
@Override
Exceptions
Exception:
if the return value handling results in an error
supportsReturnTypeback to summary
public boolean supportsReturnType(MethodParameter returnType)

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.supportsReturnType.

Always returns true. See class-level note.

Parameters
returnType:MethodParameter

Doc from org.springframework.web.method.support.HandlerMethodReturnValueHandler.supportsReturnType.

the method return type to check

Returns:boolean

Doc from org.springframework.web.method.support.HandlerMethodReturnValueHandler.supportsReturnType.

true if this handler supports the supplied return type; false otherwise

Annotations
@Override