标签:java post spring-mvc spring 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
所以我想知道为什么会有这样的限制,我找到了这个话题: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).
在那些升级之后,使用相同的代码,它的工作原理;)
标签:java,post,spring-mvc,spring,java-ee 来源: https://codeday.me/bug/20190703/1362311.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。