Class ModelAndViewResolverMethodReturnValueHandler
- All Implemented Interfaces:
HandlerMethodReturnValueHandler
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(org.springframework.core.MethodParameter)
method
cannot be implemented. Hence ModelAndViewResolver
s 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.
- Since:
- 3.1
- Author:
- Rossen Stoyanchev
-
Constructor Summary
ConstructorDescriptionModelAndViewResolverMethodReturnValueHandler
(List<ModelAndViewResolver> mavResolvers) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
handleReturnValue
(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) Handle the given return value by adding attributes to the model and setting a view or setting theModelAndViewContainer.setRequestHandled(boolean)
flag totrue
to indicate the response has been handled directly.boolean
supportsReturnType
(MethodParameter returnType) Always returnstrue
.
-
Constructor Details
-
ModelAndViewResolverMethodReturnValueHandler
public ModelAndViewResolverMethodReturnValueHandler(@Nullable List<ModelAndViewResolver> mavResolvers) Create a new instance.
-
-
Method Details
-
supportsReturnType
Always returnstrue
. See class-level note.- Specified by:
supportsReturnType
in interfaceHandlerMethodReturnValueHandler
- Parameters:
returnType
- the method return type to check- Returns:
true
if this handler supports the supplied return type;false
otherwise
-
handleReturnValue
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception Description copied from interface:HandlerMethodReturnValueHandler
Handle the given return value by adding attributes to the model and setting a view or setting theModelAndViewContainer.setRequestHandled(boolean)
flag totrue
to indicate the response has been handled directly.- Specified by:
handleReturnValue
in interfaceHandlerMethodReturnValueHandler
- Parameters:
returnValue
- the value returned from the handler methodreturnType
- the type of the return value. This type must have previously been passed toHandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
which must have returnedtrue
.mavContainer
- the ModelAndViewContainer for the current requestwebRequest
- the current request- Throws:
Exception
- if the return value handling results in an error
-