我在视图中有一个表单,它将对象发送到我的控制器,但问题是如果我发送超过256个对象,我会遇到异常:
org.springframework.beans.InvalidPropertyException: Invalid property 'followers[256]' of bean class [org.myec3.portalgen.plugins.newsletter.dto.FollowerFileDto]: Index of out of bounds in property path 'followers[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
所以我想知道为什么会有这样的限制,我找到了这个话题:https://stackoverflow.com/a/24699008/4173394
但它似乎对我不起作用(可能对我不好用).
这是我的结构:
我的视图名为createUpdate.vm,并发布我的表单如下:
<form id="createFollowerFileForm" method="post" action="#route("followerFileController.upsertFollowerFile")" enctype="multipart/form-data" class="form_styled">
我的函数upsertFollowerFile在FollowerFileController中:
@InitBinder
public void initBinder(WebDataBinder dataBinder) {
// this will allow 500 size of array.
dataBinder.setAutoGrowCollectionLimit(500);
}
@Secured({ "ROLE_SUPER_ADMIN_PORTALGEN", "ROLE_CUSTOMER_PORTALGEN", "ROLE_ADMIN_PORTALGEN", "ROLE_WRITER_PORTALGEN" })
public String upsertFollowerFile(
@ModelAttribute(value = "followerFile") FollowerFileDto followerFileDto,
BindingResult result, ModelMap model, HttpServletRequest request) {
而我的课程FollowerFileDto:
public class FollowerFileDto {
private String title;
private Long followerId;
private boolean isDeletable;
private List<FollowerDto> followers;
public FollowerFileDto() {
this.followers = new ArrayList<FollowerDto>();
}
正如您在我的控制器中看到的那样,我尝试使用@InitBinder注释设置超过256个允许的对象(500),但它根本不起作用.从不调用InitBinder函数.我做错了什么吗?
谢谢你的答案;)
最佳答案 实际上,没有读取@InitBinder,这就是未设置新集合限制的原因.我不得不将我的springmvc-router版本升级到1.2.0(这也迫使我将我的spring版本升级到3.2).
在那些升级之后,使用相同的代码,它的工作原理;)