我想通过 POST 将对象 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
}
我的 POST 是这样的:
myList[0] = 12
myList[1] = 15
myList[2] = 7
谢谢!
最佳答案
@RequestParam
不支持这种绑定(bind),所以你必须使用@ModelAttribute
:
class MyObjects {
private List<MyObject> myList;
...
}
public String action (@ModelAttribute MyObjects myObjects, Model model) { ... }
关于java - 对象列表作为 Spring MVC 中的 RequestParam,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6269042/