在 Spring MVC (3.0) 中,如何将两个 URL 路由映射到同一个处理程序方法?

发布于 2024-09-26 20:57:37 字数 533 浏览 3 评论 0原文

我有一个 userPanel 方法映射到 /user/panel URL 路由:

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

但是,我还希望 userPanel 方法来处理路由< code>/panel 而不创建如下所示的单独方法:

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

是否有办法让 userPanel 方法处理这两个路由以避免重复?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜灵血窟げ 2024-10-03 20:57:37

@RequestMapping 可以采用多个路径:

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

@RequestMapping can take multiple paths:

@RequestMapping(value = {"/user/panel", "/panel"}, method = RequestMethod.GET)
public final String userPanel(HttpServletRequest request, ModelMap model)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文