|
1 | 1 | /* |
2 | | - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
24 | 24 | import java.util.Map; |
25 | 25 | import java.util.Set; |
26 | 26 |
|
| 27 | +import org.apache.commons.logging.Log; |
| 28 | +import org.apache.commons.logging.LogFactory; |
| 29 | + |
27 | 30 | import org.springframework.beans.BeanUtils; |
28 | 31 | import org.springframework.core.Conventions; |
29 | 32 | import org.springframework.core.GenericTypeResolver; |
|
58 | 61 | */ |
59 | 62 | public final class ModelFactory { |
60 | 63 |
|
| 64 | + private static final Log logger = LogFactory.getLog(ModelFactory.class); |
| 65 | + |
| 66 | + |
61 | 67 | private final List<ModelMethod> modelMethods = new ArrayList<>(); |
62 | 68 |
|
63 | 69 | private final WebDataBinderFactory dataBinderFactory; |
@@ -135,14 +141,22 @@ private void invokeModelAttributeMethods(NativeWebRequest request, ModelAndViewC |
135 | 141 | } |
136 | 142 |
|
137 | 143 | Object returnValue = modelMethod.invokeForRequest(request, container); |
138 | | - if (!modelMethod.isVoid()){ |
139 | | - String returnValueName = getNameForReturnValue(returnValue, modelMethod.getReturnType()); |
140 | | - if (!ann.binding()) { |
141 | | - container.setBindingDisabled(returnValueName); |
142 | | - } |
143 | | - if (!container.containsAttribute(returnValueName)) { |
144 | | - container.addAttribute(returnValueName, returnValue); |
| 144 | + if (modelMethod.isVoid()) { |
| 145 | + if (StringUtils.hasText(ann.value())) { |
| 146 | + if (logger.isDebugEnabled()) { |
| 147 | + logger.debug("Name in @ModelAttribute is ignored because method returns void: " + |
| 148 | + modelMethod.getShortLogMessage()); |
| 149 | + } |
145 | 150 | } |
| 151 | + continue; |
| 152 | + } |
| 153 | + |
| 154 | + String returnValueName = getNameForReturnValue(returnValue, modelMethod.getReturnType()); |
| 155 | + if (!ann.binding()) { |
| 156 | + container.setBindingDisabled(returnValueName); |
| 157 | + } |
| 158 | + if (!container.containsAttribute(returnValueName)) { |
| 159 | + container.addAttribute(returnValueName, returnValue); |
146 | 160 | } |
147 | 161 | } |
148 | 162 | } |
|
0 commit comments