SpringMVC提交参数绑定list时,默认配置如果list大小超过256,就会报错

来源:互联网 发布:强行卸载软件 编辑:程序博客网 时间:2024/04/30 12:54
使用SpringMVC提交数组时,如果list/array 大小超过256,就会报错。


原因是DataBinder 中默认限制了list最大只能增长到256。

private int autoGrowCollectionLimit = DEFAULT_AUTO_GROW_COLLECTION_LIMIT;

解决方案:




1)在BaseController添加InitBinder方法,其余继承BaseController

@InitBinder

public void initBinder(WebDataBinder binder) {

    binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);

}

2)增加一个WebBindingInitializer类,并在xml中配置。

public class DataBindingInitializer implements WebBindingInitializer {

    @Override

    public void initBinder(WebDataBinder binde) {

        binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);

    }

}

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="webBindingInitializer">
        <bean class="xxx.DataBindingInitializer"/>
    </property>
</bean>

0 0
原创粉丝点击