Example usage for org.springframework.web.method.annotation ModelFactory getNameForReturnValue

List of usage examples for org.springframework.web.method.annotation ModelFactory getNameForReturnValue

Introduction

In this page you can find the example usage for org.springframework.web.method.annotation ModelFactory getNameForReturnValue.

Prototype

public static String getNameForReturnValue(@Nullable Object returnValue, MethodParameter returnType) 

Source Link

Document

Derive the model attribute name for the given return value.

Usage

From source file:org.springframework.web.method.annotation.ModelAttributeMethodProcessor.java

/**
 * Add non-null return values to the {@link ModelAndViewContainer}.
 *///w  w w . ja  v a2 s  .c  o m
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
        ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

    if (returnValue != null) {
        String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
        mavContainer.addAttribute(name, returnValue);
    }
}

From source file:org.springframework.web.method.annotation.support.ModelAttributeMethodProcessor.java

/**
 * Add non-null return values to the {@link ModelAndViewContainer}.
 *///from   w  ww .j a  v a2 s  .c o  m
public void handleReturnValue(Object returnValue, MethodParameter returnType,
        ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
    if (returnValue != null) {
        String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
        mavContainer.addAttribute(name, returnValue);
    }
}