In Spring MVC 3 how can you map multiple urls with query parameters ("/a" and "/b?xyz") to one handler?
"/b" has been already mapped to another handler. RequestMapping(value = {"/a","/b?xyz"}) does not see开发者_开发问答m to work.
Thanks for your help.You may try this:
@RequestMapping("/a")
public void yourMethodA() {
// do the common controller logic
}
@RequestMapping(value="/b", params = "xyz")
public void yourMethodB() {
yourMethodA(); // delegating the 1st mapped method
}
This way, you don't repeat yourself and you are able to define your mappings accurately.
If you want to map query string parameters, you shouldn't do it in the value
member of RequestMapping
, but rather in the params
member:
@RequestMapping(value={"/a", "/b"}, params = "xyz")
public void yourMethod() {
}
Of course, this will only match /a
if it also has the param xyz.
精彩评论