![](/img/trans.png)
[英]How to take LIST input in @RequestParam in Spring MVC?
[英]List of Objects as RequestParam in Spring MVC
我想通過POST將 object id 的列表(由用戶選擇復選框生成)發送到一個操作,所以我可以得到一個java.util.List<MyObject>
使用MyObjectEditor
轉換。
那么,有可能做到這一點嗎?
@InitBinder
public void initBinder (WebDataBinder binder) {
binder.registerCustomEditor(MyObject.class, new MyObjectEditor());
}
@RequestMapping (value = "", method = RequestMethod.POST)
public String action (@RequestParam List<MyObject> myList, Model model) {
// more stuff here
}
我的帖子是這樣的:
myList[0] = 12
myList[1] = 15
myList[2] = 7
謝謝!
@RequestParam
不支持這種綁定,因此您必須使用@ModelAttribute
:
class MyObjects {
private List<MyObject> myList;
...
}
public String action (@ModelAttribute MyObjects myObjects, Model model) { ... }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.