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

标签 java spring spring-mvc url-routing code-duplication

我有一个 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/

相关文章:

java - WSDL 使用 SOAP 1.2 时生成 webservice 客户端

java - Spring MVC : HTTP Status 400 - Required MultipartFile parameter 'file' is not present

java - Spring ComponentScan 导致 java.lang.IllegalStateException : ApplicationEventMulticaster not initialized

mysql - Thymeleaf 不显示来自 MySQL 的数据

spring - 测试 spring boot 1.4 应用程序时出错

spring-mvc - Spring Thymeleaf View 的正确位置

Spring 标准 Bean 注入(inject)与 Autowiring

java - 如何只绘制一次 String()

java - 找不到符号[错误]符号: method getlogger(java. lang.Class <org.first.FirstMaven.App>)

java - 序列化并不总是以序列化原始类型结束吗?