org.springframework.web.servlet.mvc.method.annotation.support
Class DefaultMethodReturnValueHandler

java.lang.Object
  extended by org.springframework.web.servlet.mvc.method.annotation.support.DefaultMethodReturnValueHandler
All Implemented Interfaces:
HandlerMethodReturnValueHandler

public class DefaultMethodReturnValueHandler
extends Object
implements HandlerMethodReturnValueHandler

Attempts to handle return value types not recognized by any other HandlerMethodReturnValueHandler. Intended to be used as the last of a list of registered handlers as supportsReturnType(MethodParameter) always returns true.

Handling takes place in the following order:

Note that ModelAndViewResolver is supported for backwards compatibility. Since the only way to check if it supports a return value type is to try to resolve the return value, a ModelAndViewResolver can only be invoked from here after no other HandlerMethodReturnValueHandler has recognized the return value. To avoid this limitation change the ModelAndViewResolver to implement HandlerMethodReturnValueHandler instead.

Since:
3.1
Author:
Rossen Stoyanchev

Constructor Summary
DefaultMethodReturnValueHandler()
          Create a DefaultMethodReturnValueHandler instance without ModelAndViewResolvers.
DefaultMethodReturnValueHandler(List<ModelAndViewResolver> mavResolvers)
          Create a DefaultMethodReturnValueHandler with a list of ModelAndViewResolvers.
 
Method Summary
 void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest request)
          Handle the given return value by adding attributes to the model, setting the view (or view name), or by writing to the response.
 boolean supportsReturnType(MethodParameter returnType)
          Whether the given method return type is supported by this handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultMethodReturnValueHandler

public DefaultMethodReturnValueHandler()
Create a DefaultMethodReturnValueHandler instance without ModelAndViewResolvers.


DefaultMethodReturnValueHandler

public DefaultMethodReturnValueHandler(List<ModelAndViewResolver> mavResolvers)
Create a DefaultMethodReturnValueHandler with a list of ModelAndViewResolvers.

Method Detail

supportsReturnType

public boolean supportsReturnType(MethodParameter returnType)
Description copied from interface: HandlerMethodReturnValueHandler
Whether the given method return type is supported by this handler.

Specified by:
supportsReturnType in interface HandlerMethodReturnValueHandler
Parameters:
returnType - the method return type to check
Returns:
true if this handler supports the supplied return type; false otherwise

handleReturnValue

public void handleReturnValue(Object returnValue,
                              MethodParameter returnType,
                              ModelAndViewContainer mavContainer,
                              NativeWebRequest request)
                       throws Exception
Description copied from interface: HandlerMethodReturnValueHandler
Handle the given return value by adding attributes to the model, setting the view (or view name), or by writing to the response. HandlerMethodReturnValueHandler implementations should also consider whether to set ModelAndViewContainer.setResolveView(boolean), which is set to true by default and therefore needs to be set to false explicitly if view resolution is to be bypassed.

Specified by:
handleReturnValue in interface HandlerMethodReturnValueHandler
Parameters:
returnValue - the value returned from the handler method
returnType - the type of the return value. This type must have previously been passed to HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter) and it must have returned true
mavContainer - the ModelAndViewContainer for the current request
request - the current request
Throws:
Exception - if the return value handling results in an error