下面給出的測試用例顯示了一個簡單的情況,其中我有2個參數paramA
和paramB
。Spring @RequestParam不能正確處理多個變量 - 示例測試用例
- 如果我調用
/paramtest
url,則調用paramtest()
方法。 - 如果我爲
paramA
輸入true
,則調用方法aTrue()
。 - 但是,當我爲
paramA
和paramB
輸入true
時,將調用方法bTrueNotA()
。
但第三@RequestMapping
呼籲A=True
和B!=true
。當兩個參數都爲真時,我應該調用aTrue()
。
@RequestMapping("paramtest")
@ResponseBody
public String paramtest(){
return "<html><head></head><body>" +
"<form action=paramtest method=post>" +
"paramA: <input type=text name=paramA /><br>" +
"paramB: <input type=text name=paramB /><br>" +
"<input type=submit>" +
"</form>" +
"</body></html>";
}
@RequestMapping(value="paramtest", params="paramA=true")
@ResponseBody
public String aTrue(){
return "A=true";
}
@RequestMapping(value="paramtest", params={"paramB=true", "paramA!=true"})
@ResponseBody
public String bTrueNotA(){
return "B=True; A!=true";
}
你使用哪個版本的彈簧? – krock 2011-03-14 08:55:24
Spring MVC Version:3.0.5 – 2011-03-14 10:33:20
如果將「paramA!= true」更改爲「!paramA = true」,會發生什麼? – StanislavL 2011-03-14 10:41:40