Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnnotationMethodHandlerAdapter should treat String return type with @ModelAttribute as model attribute instead of view name [SPR-4867] #9543

Closed
spring-projects-issues opened this issue May 27, 2008 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Joris Kuipers opened SPR-4867 and commented

Currently, AnnotationMethodHandlerAdapter.getModelAndView treats all String return types as view names. It might make sense to support returning a String as a model attribute by annotating the method with @ModelAttribute. Even though this would be an incompatible change, the combination of @ModelAttribute with a String return type is meaningless at the moment so this shouldn't cause any problems. Otherwise, I think that we should at least issue a warning if someone uses this combination.


Affects: 2.5.4

Referenced from: commits 72cc060

@spring-projects-issues
Copy link
Collaborator Author

Joris Kuipers commented

Oh, BTW: this goes for a Map being returned as well. Just check for the presence of @ModelAttribute first, before going over the other supported return types.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point! Makes sense for request handler methods with an @ModelAttribute annotation to always return a model attribute.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Neale Upstone commented

Any chance of documenting this in the @ModelAttribute javadoc. I don't really think I should have needed to go to the Source tab to see your deltas to understand how this works... but... at least the code is self explanatory :)

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 M3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants