Description
Doug Gschwind opened SPR-7585 and commented
The RequestMapping annotation does a great job of helping the reader of a Spring MVC Controller understand which method(s) on that Controller will be invoked given a URI such as "/account", the HTTP method (e.g. GET or POST), as well as given the presence/absence of certain identified HTTP request parameters.
I believe this implementation suffers from the following though, and hence could be improved to address these concerns :
- These URIs embedded in a Spring MVC Controller are the source of Don't Repeat Yourself violations since that same URI has to be repeated elsewhere in say a JSP that has a hyperlink or a button that intends to invoke a given method on a given type of Controller when the hyperlink or button is clicked upon.
- Spring MVC does not appear to have a facility to be able to generate a URL in say a JSP, that intends to invoke a given method on a given type of Controller. This is closely related to the first item.
- By having these URIs sprinkled throughout your Spring MVC Controller classes, you have a little bit of research to do if you plan to introduce a new Controller that should have a distinct URI that it responds to. A text search through the source files would solve that problem, but that is slow and error prone. I understand the Spring MVC plugin for Eclipse has some support for this, but once again requires the human eye to review all the existing URIs to determine if there exists a collision or partial URI match of some sort.
I have tried to solve one and two by placing information in the Spring MVC descriptor, but that involves interrogating the ApplicationContext, and of course, my own custom code. I would like the framework to provide this support for me, so that I have to specify a URI for a Controller and Method, once and only once. If that were possible, I could make a URI change in one place, and the app would continue to run fine (assuming that change introduced no [partial] collisions) without any further effort.
Thank you,
Doug Gschwind
Affects: 3.0 GA
Issue Links:
- Allow links to @Controller methods from views without hardcoding URLs [SPR-5779] #10449 Allow links to
@Controller
methods from views without hardcoding URLs ("duplicates")