|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -24,6 +24,9 @@ import java.util.List;
@@ -24,6 +24,9 @@ import java.util.List;
|
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.core.Conventions; |
|
|
|
|
import org.springframework.core.GenericTypeResolver; |
|
|
|
|
@ -58,6 +61,9 @@ import org.springframework.web.method.support.ModelAndViewContainer;
@@ -58,6 +61,9 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
|
|
|
|
*/ |
|
|
|
|
public final class ModelFactory { |
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(ModelFactory.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<ModelMethod> modelMethods = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
private final WebDataBinderFactory dataBinderFactory; |
|
|
|
|
@ -135,14 +141,22 @@ public final class ModelFactory {
@@ -135,14 +141,22 @@ public final class ModelFactory {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
if (modelMethod.isVoid()) { |
|
|
|
|
if (StringUtils.hasText(ann.value())) { |
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
logger.debug("Name in @ModelAttribute is ignored because method returns void: " + |
|
|
|
|
modelMethod.getShortLogMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String returnValueName = getNameForReturnValue(returnValue, modelMethod.getReturnType()); |
|
|
|
|
if (!ann.binding()) { |
|
|
|
|
container.setBindingDisabled(returnValueName); |
|
|
|
|
} |
|
|
|
|
if (!container.containsAttribute(returnValueName)) { |
|
|
|
|
container.addAttribute(returnValueName, returnValue); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|