In Spring MVC 3 I want to handle the same url with two different controller classes - depending on value of url parameter. @RequestMapping annotation even has such field: params, and I thought following would be two different mappings (I use mapping on class level):
@RequestMapping(value = "/myurl", params = "name=val1")
and
@RequestMapping(value = "/myurl", params = "name=val2")
but it's not. Spring throws exception for second case that controller for /myurl already mapped (by first case).
Is there some accurate solution for splitting request mapping by parameter? May be extending @RequestMapping or using proxy as controller and call different controllers depending on parameter... Any thoughts?
UPDATE This works but only on methods level, not on class level... This will:
@Controller
@RequestMapping(value = "/myurl")
public class Class123 {
@RequestMapping(value = {"edit.htm"}, params = "src=1")
public String open1(Map<String, Object> map) throws Exception {....}
@RequestMapping(value = {"edit.htm"}, params = "src=2")
public String open2(Map<String, Object> map) throws Exception {....}
}
this won't:
@Controller
@RequestMapping(value = "/myurl", params = "src=1")
public class Class123_1 {
@RequestMapping(value = {"edit.htm"})
public String open(Map<String, Object> map) throws Exception {....}
}
@Controller
@RequestMapping(value = "/myurl", params = "src=2")
public class Class123_2 {
@RequestMapping(value = {"edit.htm"})
public String open(Map<String, Object> map) throws Exception {....}
}
And I would like to split logic in different classes.
It sounds like a difference between using RequestMappingHandlerMapping (new in Spring 3.1) vs DefaultAnnotationHandlerMapping (the class replaced by RequestMappingHandlerMapping).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With