开发者

How can you have two URL routes mapped to the same handler method in Spring MVC (3.0)?

开发者 https://www.devze.com 2023-01-19 22:38 出处:网络
I have a a userPanel method mapped to the /user/panel URL route: @RequestMapping(value = \"/user/panel\", method = RequestMethod.GET)

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 开发者_Python百科userPanel method handle both routes to avoid duplication?


@RequestMapping can take multiple paths:

@RequestMapping(value = {"/user/panel", "/panel"}, method = RequestMethod.GET)
public final String userPanel(HttpServletRequest request, ModelMap model)
0

精彩评论

暂无评论...
验证码 换一张
取 消