Log*_*aul 5 java post spring spring-mvc java-ee
我的视图中有一个将对象发送到控制器的表单,但是问题是,如果我发送的对象超过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
Run Code Online (Sandbox Code Playgroud)
所以我想知道为什么会有这样的限制,所以我找到了这个主题:https : //stackoverflow.com/a/24699008/4173394
但这似乎对我不起作用(可能是我的不当使用)。
这是我的结构:我的视图称为createUpdate.vm,并像这样发布我的表单:
<form id="createFollowerFileForm" method="post" action="#route("followerFileController.upsertFollowerFile")" enctype="multipart/form-data" class="form_styled">
Run Code Online (Sandbox Code Playgroud)
我的函数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) {
Run Code Online (Sandbox Code Playgroud)
和我的类FollowerFileDto:
public class FollowerFileDto {
private String title;
private Long followerId;
private boolean isDeletable;
private List<FollowerDto> followers;
public FollowerFileDto() {
this.followers = new ArrayList<FollowerDto>();
}
Run Code Online (Sandbox Code Playgroud)
正如您在控制器中看到的那样,我尝试使用@InitBinder注释设置超过256个允许的对象(500),但这根本不起作用。永远不会调用InitBinder函数。我做错了什么吗?谢谢你的回答;)
实际上,@InitBinder 没有被读取,这就是为什么没有设置新的集合限制。我不得不将 springmvc-router 版本升级到 1.2.0 (这也迫使我将 spring 版本升级到 3.2)。
升级后,使用相同的代码,它可以工作;)
| 归档时间: |
|
| 查看次数: |
2217 次 |
| 最近记录: |