Skip to content

@ModelAttribute (method level for reference data) default names could be made more useful [SPR-4264] #8942

Closed
@spring-projects-issues

Description

@spring-projects-issues

Tom Mack opened SPR-4264 and commented

AnnotationMethodHandlerAdapter simply calls implicitModel.addAttribute(attrValue) [around line 228] when an explicit value isn't set on the attribute. It is my opinion that one of the following would be more useful:

  1. Determine the attrName from the name of the annotated method. If the method was called getImportantData, the attrName could be set to "importantData". If the method name didn't start with a get/is, the attrName could simple be equal to the method name.

  2. Instead of simply delegating to the ModelMap class, uses its conventions but apply them to the return type of the method. I'm not a huge fan of the getVariableName idea, but it would be more useful if it took into account the declared return type. If I have a method called "List<SomeBaseClass> getImportantData()", the attrName could be "someBaseClassList" (which is better than arbitrarily picking the class of one item in the list).

I like #1, this is what I expected to happen before I tried it. It also seems to follow how @RequestMapping works when no value is declared. But, I can see how #2 is a smaller change from how it currently works.


Affects: 2.5 final

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions