laf*_*ste 4 spring spring-mvc request-mapping
我喜欢将所有映射保存在同一个地方,所以我使用XML配置:
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/video/**=videoControllerr
/blog/**=blogController
</value>
</property>
<property name="alwaysUseFullPath">
<value>true</value>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
如果我在不同的控制器中创建具有相同名称的第二个请求映射,
@Controller
public class BlogController {
@RequestMapping(value = "/info", method = RequestMethod.GET)
public String info(@RequestParam("t") String type) {
// Stuff
}
}
@Controller
public class VideoController {
@RequestMapping(value = "/info", method = RequestMethod.GET)
public String info() {
// Stuff
}
}
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
Caused by: java.lang.IllegalStateException: Cannot map handler 'videoController' to URL path [/info]: There is already handler of type [class com.cyc.cycbiz.controller.BlogController] mapped.
Run Code Online (Sandbox Code Playgroud)
有没有办法在不同的控制器中使用相同的请求映射?
我想要2个网址:
/video/info.html
/blog/info.html
Run Code Online (Sandbox Code Playgroud)
使用Spring MVC 3.1.1
编辑: 我不是唯一一个:https: //spring.io/blog/2008/03/24/using-a-hybrid-annotations-xml-approach-for-request-mapping-in-spring-mvc
应用程序的其余部分完美运行.
只需将一个请求映射放在Controller的级别:
@Controller
@RequestMapping("/video")
public class VideoController {
@RequestMapping(value = "/info", method = RequestMethod.GET)
public String info() {
// Stuff
}
}
@Controller
@RequestMapping("/blog")
public class BlogController {
@RequestMapping(value = "/info", method = RequestMethod.GET)
public String info(@RequestParam("t") String type) {
// Stuff
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9404 次 |
最近记录: |