Example usage for org.springframework.web.method.support InvocableHandlerMethod getMethodAnnotation

List of usage examples for org.springframework.web.method.support InvocableHandlerMethod getMethodAnnotation

Introduction

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

Prototype

@Nullable
public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType) 

Source Link

Document

Return a single annotation on the underlying method traversing its super methods if no annotation can be found on the given method itself.

Usage

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

/**
 * Invoke model attribute methods to populate the model.
 * Attributes are added only if not already present in the model.
 *//* w  w  w .  j  a  v  a  2s.com*/
private void invokeModelAttributeMethods(NativeWebRequest request, ModelAndViewContainer container)
        throws Exception {

    while (!this.modelMethods.isEmpty()) {
        InvocableHandlerMethod modelMethod = getNextModelMethod(container).getHandlerMethod();
        ModelAttribute ann = modelMethod.getMethodAnnotation(ModelAttribute.class);
        Assert.state(ann != null, "No ModelAttribute annotation");
        if (container.containsAttribute(ann.name())) {
            if (!ann.binding()) {
                container.setBindingDisabled(ann.name());
            }
            continue;
        }

        Object returnValue = modelMethod.invokeForRequest(request, container);
        if (!modelMethod.isVoid()) {
            String returnValueName = getNameForReturnValue(returnValue, modelMethod.getReturnType());
            if (!ann.binding()) {
                container.setBindingDisabled(returnValueName);
            }
            if (!container.containsAttribute(returnValueName)) {
                container.addAttribute(returnValueName, returnValue);
            }
        }
    }
}