public class ModelAndViewResolverMethodReturnValueHandler extends java.lang.Object implements 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.
Modifier and Type | Field and Description |
---|---|
private java.util.List<ModelAndViewResolver> |
mavResolvers |
private ModelAttributeMethodProcessor |
modelAttributeProcessor |
Constructor and Description |
---|
ModelAndViewResolverMethodReturnValueHandler(java.util.List<ModelAndViewResolver> mavResolvers)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
handleReturnValue(java.lang.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 the
ModelAndViewContainer.setRequestHandled(boolean) flag to true
to indicate the response has been handled directly. |
boolean |
supportsReturnType(MethodParameter returnType)
Always returns
true . |
private final java.util.List<ModelAndViewResolver> mavResolvers
private final ModelAttributeMethodProcessor modelAttributeProcessor
public ModelAndViewResolverMethodReturnValueHandler(java.util.List<ModelAndViewResolver> mavResolvers)
public boolean supportsReturnType(MethodParameter returnType)
true
. See class-level note.supportsReturnType
in interface HandlerMethodReturnValueHandler
returnType
- the method return type to checktrue
if this handler supports the supplied return type;
false
otherwisepublic void handleReturnValue(java.lang.Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws java.lang.Exception
HandlerMethodReturnValueHandler
ModelAndViewContainer.setRequestHandled(boolean)
flag to true
to indicate the response has been handled directly.handleReturnValue
in interface HandlerMethodReturnValueHandler
returnValue
- the value returned from the handler methodreturnType
- the type of the return value. This type must have
previously been passed to HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
which must
have returned true
.mavContainer
- the ModelAndViewContainer for the current requestwebRequest
- the current requestjava.lang.Exception
- if the return value handling results in an error