I want to send a list of object id's (generated by the user selecting checkboxes) by POST to an action, so I can get a java.util.List<MyObject>
converted using an My开发者_StackOverflow社区ObjectEditor
.
So, is it possible to do this?
@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
}
And my POST would be like this:
myList[0] = 12
myList[1] = 15
myList[2] = 7
Thanks!
This kind of binding is not supported by @RequestParam
, so you have to use @ModelAttribute
:
class MyObjects {
private List<MyObject> myList;
...
}
public String action (@ModelAttribute MyObjects myObjects, Model model) { ... }
精彩评论