我想通过 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不支持这种绑定,因此您必须使用@ModelAttribute:

class MyObjects {
    private List<MyObject> myList;
    ...
}

public String action (@ModelAttribute MyObjects myObjects, Model model) { ... }

09-26 23:01
查看更多