开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜