How can you have two URL routes mapped to the same handler method in Spring MVC (3.0)?
-
29-09-2019 - |
Question
I have a a userPanel
method mapped to the /user/panel
URL route:
@RequestMapping(value = "/user/panel", method = RequestMethod.GET)
public final String userPanel(HttpServletRequest request, ModelMap model)
However, I would also like the userPanel
method to handle the route /panel
without creating a separate method such as this:
@RequestMapping(value = "/panel", method = RequestMethod.GET)
public final String panel(HttpServletRequest request, ModelMap model)
Is there a way to have the userPanel
method handle both routes to avoid duplication?
Solution
@RequestMapping
can take multiple paths:
@RequestMapping(value = {"/user/panel", "/panel"}, method = RequestMethod.GET)
public final String userPanel(HttpServletRequest request, ModelMap model)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow