Example usage for org.springframework.web.method.support HandlerMethodReturnValueHandler handleReturnValue

List of usage examples for org.springframework.web.method.support HandlerMethodReturnValueHandler handleReturnValue

Introduction

In this page you can find the example usage for org.springframework.web.method.support HandlerMethodReturnValueHandler handleReturnValue.

Prototype

void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
        ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception;

Source Link

Document

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.

Usage

From source file:org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.java

/**
 * Iterate over registered {@link HandlerMethodReturnValueHandler}s and invoke the one that supports it.
 * @throws IllegalStateException if no suitable {@link HandlerMethodReturnValueHandler} is found.
 *//*from  www  .ja v  a2 s  . c  om*/
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
        ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

    HandlerMethodReturnValueHandler handler = selectHandler(returnValue, returnType);
    if (handler == null) {
        throw new IllegalArgumentException(
                "Unknown return value type: " + returnType.getParameterType().getName());
    }
    handler.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
}