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

使用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>

猜你喜欢

转载自hightao.iteye.com/blog/2302683