Java Spring MVC中作为RequestParam的对象列表
我想通过POST将对象id列表(由用户选择复选框生成)发送到一个操作,这样我就可以使用Java Spring MVC中作为RequestParam的对象列表,java,spring,spring-mvc,Java,Spring,Spring Mvc,我想通过POST将对象id列表(由用户选择复选框生成)发送到一个操作,这样我就可以使用MyObjectEditor转换java.util.list 那么,有可能做到这一点吗 @InitBinder public void initBinder (WebDataBinder binder) { binder.registerCustomEditor(MyObject.class, new MyObjectEditor()); } @RequestMapping (value = "", m
MyObjectEditor
转换java.util.list
那么,有可能做到这一点吗
@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
}
谢谢 这种绑定不受
@RequestParam
支持,因此必须使用@modeldattribute
:
class MyObjects {
private List<MyObject> myList;
...
}
public String action (@ModelAttribute MyObjects myObjects, Model model) { ... }
类MyObjects{
私人名单;
...
}
公共字符串操作(@modeldattribute MyObjects MyObjects,Model Model){…}
@axtavt:是否有其他方法映射列表?我知道我们可以用包装物来做,但有时这太过分了。有人绕过过这个吗?
class MyObjects {
private List<MyObject> myList;
...
}
public String action (@ModelAttribute MyObjects myObjects, Model model) { ... }