@@ -185,44 +185,6 @@ private List<String> findSessionAttributeArguments(HandlerMethod handlerMethod)
185185 return result ;
186186 }
187187
188- /**
189- * Derives the model attribute name for a method parameter based on:
190- * <ol>
191- * <li>The parameter {@code @ModelAttribute} annotation value
192- * <li>The parameter type
193- * </ol>
194- * @return the derived name; never {@code null} or an empty string
195- */
196- public static String getNameForParameter (MethodParameter parameter ) {
197- ModelAttribute ann = parameter .getParameterAnnotation (ModelAttribute .class );
198- String name = (ann != null ? ann .value () : null );
199- return StringUtils .hasText (name ) ? name : Conventions .getVariableNameForParameter (parameter );
200- }
201-
202- /**
203- * Derive the model attribute name for the given return value using one of:
204- * <ol>
205- * <li>The method {@code ModelAttribute} annotation value
206- * <li>The declared return type if it is more specific than {@code Object}
207- * <li>The actual return value type
208- * </ol>
209- * @param returnValue the value returned from a method invocation
210- * @param returnType the return type of the method
211- * @return the model name, never {@code null} nor empty
212- */
213- public static String getNameForReturnValue (Object returnValue , MethodParameter returnType ) {
214- ModelAttribute ann = returnType .getMethodAnnotation (ModelAttribute .class );
215- if (ann != null && StringUtils .hasText (ann .value ())) {
216- return ann .value ();
217- }
218- else {
219- Method method = returnType .getMethod ();
220- Class <?> containingClass = returnType .getContainingClass ();
221- Class <?> resolvedType = GenericTypeResolver .resolveReturnType (method , containingClass );
222- return Conventions .getVariableNameForReturnType (method , resolvedType , returnValue );
223- }
224- }
225-
226188 /**
227189 * Promote model attributes listed as {@code @SessionAttributes} to the session.
228190 * Add {@link BindingResult} attributes where necessary.
@@ -278,6 +240,46 @@ private boolean isBindingCandidate(String attributeName, Object value) {
278240 }
279241
280242
243+ /**
244+ * Derive the model attribute name for a method parameter based on:
245+ * <ol>
246+ * <li>the parameter {@code @ModelAttribute} annotation value
247+ * <li>the parameter type
248+ * </ol>
249+ * @param parameter a descriptor for the method parameter
250+ * @return the derived name (never {@code null} or empty String)
251+ */
252+ public static String getNameForParameter (MethodParameter parameter ) {
253+ ModelAttribute ann = parameter .getParameterAnnotation (ModelAttribute .class );
254+ String name = (ann != null ? ann .value () : null );
255+ return (StringUtils .hasText (name ) ? name : Conventions .getVariableNameForParameter (parameter ));
256+ }
257+
258+ /**
259+ * Derive the model attribute name for the given return value based on:
260+ * <ol>
261+ * <li>the method {@code ModelAttribute} annotation value
262+ * <li>the declared return type if it is more specific than {@code Object}
263+ * <li>the actual return value type
264+ * </ol>
265+ * @param returnValue the value returned from a method invocation
266+ * @param returnType a descriptor for the return type of the method
267+ * @return the derived name (never {@code null} or empty String)
268+ */
269+ public static String getNameForReturnValue (Object returnValue , MethodParameter returnType ) {
270+ ModelAttribute ann = returnType .getMethodAnnotation (ModelAttribute .class );
271+ if (ann != null && StringUtils .hasText (ann .value ())) {
272+ return ann .value ();
273+ }
274+ else {
275+ Method method = returnType .getMethod ();
276+ Class <?> containingClass = returnType .getContainingClass ();
277+ Class <?> resolvedType = GenericTypeResolver .resolveReturnType (method , containingClass );
278+ return Conventions .getVariableNameForReturnType (method , resolvedType , returnValue );
279+ }
280+ }
281+
282+
281283 private static class ModelMethod {
282284
283285 private final InvocableHandlerMethod handlerMethod ;
0 commit comments