-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Willie Wheeler opened SPR-9153 and commented
In web apps, it's useful to create a base CRUD controller and then extend that with entity-specific subclasses. This makes it easy to write general purpose HTML, XML and JSON endpoints. I typically define for each subclass a class-level @RequestMapping specifying the base path for that controller (e.g., /applications, /packages, /farms, etc). Then the method-level @RequestMappings have value = "" for list views, value = "/{id}" for details views, etc.
For the web service list views, I would like to be able to map paths like /applications.xml, /applications.json, etc. But it doesn't seem that I can do this without giving up the generality in the approach above. I'd have to drop the class-level @RequestMapping, write a bunch of wrapper methods on each subclass, and then annotate them with explicit @RequestMappings to get the desired paths. Blech. Instead, I just define a generic @RequestMapping in the base controller like this:
@RequestMapping(value = "", method = RequestMethod.GET, params = "format=json")
@RequestMapping(value = "", method = RequestMethod.GET, params = "format=xml")
That works, and it's generic, but I'd like to be able to use extensions instead, just because I think it's a little cleaner.
My proposal is that you add an extension element to the @RequestMapping. I envision it working something like this:
@RequestMapping(value = "", method = RequestMethod.GET, extension = "json")
@RequestMapping(value = "", method = RequestMethod.GET, extension = "xml")
Thanks.
Affects: 3.1.1
Issue Links:
- Content negotiation improvements [SPR-8410] #13057 Content negotiation improvements