Spring Web MVC: Use same request mapping for request parameter and path variable
Posted
by ngeek
on Stack Overflow
See other posts from Stack Overflow
or by ngeek
Published on 2010-04-30T15:04:56Z
Indexed on
2010/04/30
15:07 UTC
Read the original article
Hit count: 643
Good people:
is there a way to express that my Spring Web MVC controller method should be matched either by a request handing in a ID as part of the URI path ...
@RequestMapping(method=RequestMethod.GET, value="campaigns/{id}")
public String getCampaignDetails(Model model, @PathVariable("id") Long id) {
... or if the client sends in the ID as a HTTP request parameter in the style ...
@RequestMapping(method=RequestMethod.GET, value="campaigns")
public String getCampaignDetails(Model model, @RequestParam("id") Long id) {
This seems to me a quite common real-world URL scheme where I don't want to add duplicate code, but I wasn't able to find an answer yet. Any advice highly welcome.
© Stack Overflow or respective owner