否定 Spring 控制器的 RequestMapping 中的参数
您好,
我的控制器中有两种方法,我试图在参数为某个值时触发一种方法,在参数不是该值时触发另一种方法。当参数等于某个值时,我的“not”方法就会触发。
根据(我的理解)这个 我正确地编写了表达式。以下是这两个方法的签名:
@RequestMapping(value = "/doit", params= {"output=grouped", "display!=1"})
public @ResponseBody HashMap<String, Object> doSomething(
@RequestParam("text") String text,
@RequestParam("display") String display)
{
// this method runs if display=1 but why?
}
@RequestMapping(value = "/doit", params= {"output=grouped", "display=1"})
public @ResponseBody HashMap<String, Object> doSomethingElse(
@RequestParam("text") String text)
{
// this method is not being called when display=1...why not?
}
我启用了 Spring 调试日志记录,并且看到 Spring 将参数转换为值为“1”的 RequestParam 字符串。然而,在下一行中,它决定将其映射到错误的方法。
我做错了什么?
谢谢!
Hi,
I've got two methods in my controller and I'm trying to get one method to fire if a parameter is a certain value and the other method if the parameter is not that value. My "not" method is firing when the param equals the certain value.
According to (my understanding of) this I'm writing the expression correctly. Here are the signatures of the two methods:
@RequestMapping(value = "/doit", params= {"output=grouped", "display!=1"})
public @ResponseBody HashMap<String, Object> doSomething(
@RequestParam("text") String text,
@RequestParam("display") String display)
{
// this method runs if display=1 but why?
}
@RequestMapping(value = "/doit", params= {"output=grouped", "display=1"})
public @ResponseBody HashMap<String, Object> doSomethingElse(
@RequestParam("text") String text)
{
// this method is not being called when display=1...why not?
}
I have Spring debug logging enabled and I see where Spring converts the parameter to a RequestParam String with value '1'. In the very next line, though, it decides to map it to the wrong method.
What am I doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是你的错:这是一个 Bug SPR-8059。目前它已在版本 3.1M2 和 svn 干线版本 4408。
解决方法是不在
@RequestMapping
中使用!=
。相反,您必须手动使用if
来完成此操作:It is not your fault: it is a Bug SPR-8059. At the moment it is fixed in Version 3.1M2 and svn Trunk rev 4408.
A workaround would be not to use
!=
in@RequestMapping
. Instead you have to do it with anif
by hand: