SPRING接收前台传入List时,超过256报IndexOutOfBoundsException异常

框架:spring
现象:jsp页面使用foreach循环输出list,保存时并将修改后的值返回给后台页面。
异常:org.springframework.beans.InvalidPropertyException: Invalid property 'list[256]' of bean class [...]: Index of out of bounds in property path 'list[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256 
在jsp传值时直接保存,并没有进入后台
原因:DataBinder中有如下定义:

public class DataBinder implements PropertyEditorRegistry, TypeConverter {  
  
    /** Default object name used for binding: "target" */  
    public static final String DEFAULT_OBJECT_NAME = "target";  
  
    /** Default limit for array and collection growing: 256 */  
    public static final int DEFAULT_AUTO_GROW_COLLECTION_LIMIT = 256;  
  
    private int autoGrowCollectionLimit = DEFAULT_AUTO_GROW_COLLECTION_LIMIT;  

解决方法:在自己的Controller类中,加入以下代码
 @InitBinder  
    protected void initBinder(WebDataBinder binder) {  
        binder.setAutoGrowNestedPaths(true);  
        binder.setAutoGrowCollectionLimit(1024);  
    }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值