我有一个 userPanel
方法映射到 /user/panel
网址路由:
@RequestMapping(value = "/user/panel", method = RequestMethod.GET)
public final String userPanel(HttpServletRequest request, ModelMap model)
不过,我也想要
userPanel
处理路由的方法 /panel
无需创建单独的方法,例如:@RequestMapping(value = "/panel", method = RequestMethod.GET)
public final String panel(HttpServletRequest request, ModelMap model)
有没有办法让
userPanel
方法处理两条路线以避免重复?
最佳答案
@RequestMapping
可以采取多条路径:
@RequestMapping(value = {"/user/panel", "/panel"}, method = RequestMethod.GET)
public final String userPanel(HttpServletRequest request, ModelMap model)
关于java - 如何将两个 URL 路由映射到 Spring MVC (3.0) 中的同一个处理程序方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3919706/