@@ -136,10 +136,10 @@ public final Object invokeHandlerMethod(Method handlerMethod, Object handler,
136
136
Object attrValue = doInvokeMethod (attributeMethodToInvoke , handler , args );
137
137
String attrName = AnnotationUtils .findAnnotation (attributeMethodToInvoke , ModelAttribute .class ).value ();
138
138
if ("" .equals (attrName )) {
139
- Class resolvedType =
140
- GenericTypeResolver . resolveReturnType ( attributeMethodToInvoke , handler .getClass ());
141
- attrName =
142
- Conventions . getVariableNameForReturnType ( attributeMethodToInvoke , resolvedType , attrValue );
139
+ Class resolvedType = GenericTypeResolver . resolveReturnType (
140
+ attributeMethodToInvoke , handler .getClass ());
141
+ attrName = Conventions . getVariableNameForReturnType (
142
+ attributeMethodToInvoke , resolvedType , attrValue );
143
143
}
144
144
implicitModel .addAttribute (attrName , attrValue );
145
145
}
@@ -156,10 +156,8 @@ public final Object invokeHandlerMethod(Method handlerMethod, Object handler,
156
156
}
157
157
158
158
@ SuppressWarnings ("unchecked" )
159
- private Object [] resolveHandlerArguments (Method handlerMethod ,
160
- Object handler ,
161
- NativeWebRequest webRequest ,
162
- ExtendedModelMap implicitModel ) throws Exception {
159
+ private Object [] resolveHandlerArguments (Method handlerMethod , Object handler ,
160
+ NativeWebRequest webRequest , ExtendedModelMap implicitModel ) throws Exception {
163
161
164
162
Class [] paramTypes = handlerMethod .getParameterTypes ();
165
163
Object [] args = new Object [paramTypes .length ];
@@ -446,7 +444,6 @@ protected Object resolveRequestBody(MethodParameter methodParam, NativeWebReques
446
444
throws Exception {
447
445
448
446
HttpInputMessage inputMessage = createHttpInputMessage (webRequest );
449
-
450
447
Class paramType = methodParam .getParameterType ();
451
448
MediaType contentType = inputMessage .getHeaders ().getContentType ();
452
449
if (contentType == null ) {
@@ -463,16 +460,14 @@ protected Object resolveRequestBody(MethodParameter methodParam, NativeWebReques
463
460
}
464
461
}
465
462
}
466
-
467
463
throw new HttpMediaTypeNotSupportedException (contentType , allSupportedMediaTypes );
468
464
}
469
465
470
466
/**
471
- * Returns a {@link HttpInputMessage} for the given {@link NativeWebRequest}.
467
+ * Return a {@link HttpInputMessage} for the given {@link NativeWebRequest}.
472
468
* Throws an UnsupportedOperationException by default.
473
469
*/
474
470
protected HttpInputMessage createHttpInputMessage (NativeWebRequest webRequest ) throws Exception {
475
-
476
471
throw new UnsupportedOperationException ("@RequestBody not supported" );
477
472
}
478
473
@@ -585,10 +580,8 @@ else if (this.methodResolver.isSessionAttribute(name, paramType)) {
585
580
}
586
581
587
582
@ SuppressWarnings ("unchecked" )
588
- public final void updateModelAttributes (Object handler ,
589
- Map mavModel ,
590
- ExtendedModelMap implicitModel ,
591
- NativeWebRequest webRequest ) throws Exception {
583
+ public final void updateModelAttributes (Object handler , Map <String , Object > mavModel ,
584
+ ExtendedModelMap implicitModel , NativeWebRequest webRequest ) throws Exception {
592
585
593
586
if (this .methodResolver .hasSessionAttributes () && this .sessionStatus .isComplete ()) {
594
587
for (String attrName : this .methodResolver .getActualSessionAttributeNames ()) {
@@ -692,11 +685,22 @@ protected Object resolveCommonArgument(MethodParameter methodParameter, NativeWe
692
685
}
693
686
694
687
protected Object resolveStandardArgument (Class parameterType , NativeWebRequest webRequest ) throws Exception {
695
-
696
688
if (WebRequest .class .isAssignableFrom (parameterType )) {
697
689
return webRequest ;
698
690
}
699
691
return WebArgumentResolver .UNRESOLVED ;
700
692
}
701
693
694
+ protected final void addReturnValueAsModelAttribute (
695
+ Method handlerMethod , Class handlerType , Object returnValue , ExtendedModelMap implicitModel ) {
696
+
697
+ ModelAttribute attr = AnnotationUtils .findAnnotation (handlerMethod , ModelAttribute .class );
698
+ String attrName = (attr != null ? attr .value () : "" );
699
+ if ("" .equals (attrName )) {
700
+ Class resolvedType = GenericTypeResolver .resolveReturnType (handlerMethod , handlerType );
701
+ attrName = Conventions .getVariableNameForReturnType (handlerMethod , resolvedType , returnValue );
702
+ }
703
+ implicitModel .addAttribute (attrName , returnValue );
704
+ }
705
+
702
706
}
0 commit comments