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(MethodParameter) 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.
- since:
- 3.1
- Author:
- Rossen stoyanchev
-
Constructor summary
ConstructorsConstructorDescriptionModelAndViewResolverMethodReturnValueHandler(@Nullable List<ModelAndViewResolver> mavResolvers) Create a new instance. -
Method summary
Modifier and TypeMethodDescriptionvoidhandleReturnValue(@Nullable 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 totrueto indicate the response has been handled directly.booleansupportsReturnType(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 interface HandlerMethodReturnValueHandler- Parameters:
returnType- the method return type to check- Returns:
trueif this handler supports the supplied return type;falseotherwise
-
handleReturnValue
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception Description copied from interface: HandlerMethodReturnValueHandlerHandle the given return value by adding attributes to the model and setting a view or setting theModelAndViewContainer.setRequestHandled(boolean)flag totrueto indicate the response has been handled directly.- specified by:
handleReturnValue in interface HandlerMethodReturnValueHandler- Parameters:
returnValue- the value returned from the handler methodreturnType- the type of the return value. This type must have previously been passed toHandlerMethodReturnValueHandler.supportsReturnType(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
-