0
私はArrayList
フィールドでDTO(豆)を持っている:私は私のinitBinderでSpring MVCバインディング:ArrayListをバインドする方法<...>?
public MyDTO {
...
private List<MyThing> things;
...
... getters, setters and so on
}
:
@InitBinder
public void initBinder(WebDataBinder binder) {
...
binder.registerCustomEditor(List.class, "things", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
List<MyThing> things = new ArrayList<MyThings>;
// fill things array with data from text
...
// On that stage things value is correct!
super.setValue(things);
}
});
}
そして、私のコントローラ要求メソッドで:
@RequestMapping({"save"})
public ModelAndView doSaveMyDTO(@ModelAttribute MyDTO myDTO) {
// very strange myDTO comes here=(
}
問題は私がregisterCustomEditor
のスタッフにいる間にthings
の配列が大丈夫だということです。
しかし、私はdoSaveMyDTO
方法を取得 - MyDTO.things
は、実際の値の1つの素子配列の配列のようになります。
(initBinder中のもの):
[value1, value2, value3]
は(doSaveMyDTOでmyDTO.getThingsを取得します()):
[[value1], [value2], [value3]]
なぜですか?要求が正しく形成されている場合は...
残念ながら私は、JSON文字列として私のリストを持っている...とにかく、あなたのアドバイスに感謝を必要とするだろう - 私はそれで作ってみるよをあなたの方法... – leshka
ああ、json別のものです。あなたのjsonはどのように見えるのですか?そしてそれについては、あなたには多くの必要があると思います@RequestBody – Bozho