【发布时间】:2014-12-02 15:27:31
【问题描述】:
我的视图中有一个表单,可以将对象发送到我的控制器,但问题是,如果我发送的对象超过 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">
我在 FollowerFileController 中的函数 upsertFollowerFile :
@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 函数永远不会被调用。我做错什么了吗? 谢谢你的回答;)
【问题讨论】:
-
您可以尝试不带 Secured 注释的 initBinder。不应该是 upserFollowerFile 吗?
-
我尝试评论@Secured,但我遇到了同样的问题。
-
你真的需要 multipart/form-data 吗?
-
可能不会。我尝试不使用 multipart/form-data,它的工作原理相同:小于 256 可以,超过 257 的堆栈跟踪相同。
-
您能否在最初的问题中指定您正在使用的 RequestMapping 方法?
标签: java spring spring-mvc jakarta-ee post