0

我正在尝试将表单发布到控制器,然后将数据绑定到 POJO 对象。这是 POST 数据:

model  = M12345
//one or more hidden fileds with name 'images'
images = a.jpg
images = b.jpg
......

POJO 对象如下所示:

public class ProductForm {
   String model;
   String[] images;
}

控制器代码:

ProductForm form = Form.form(ProductForm.class).bindFromRequest().get();

我期待form.images包含所有 POST 图像值。例如['a.jpg', 'b.jpg'],但我只有一个值['a.jpg']。我试图将 POST 数据更改为

model    = M12345
images[] = a.jpg
images[] = b.jpg

但我有一个例外:

InvalidPropertyException: Invalid property 'images[0]' of bean class [forms.product.ProductForm]: Invalid array index in property path 'images[0]'; nested exception is java.lang.ArrayIndexOutOfBoundsException

我能怎么做?非常感谢您的帮助!

4

1 回答 1

0

如果这是 JSON,则数组应如下所示:

images: [
   a.jpg,
   b.jpg
]  
于 2013-09-24T05:00:39.940 回答