簡體   English   中英

Spring MVC 中作為 RequestParam 的對象列表

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM