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

it2025-12-20  8

使用SpringMVC提交数组时,如果list/array 大小超过256,就会报错。 原因是DataBinder 中默认限制了list最大只能增长到256。需要重新定义提交数组的最大长度

解决方案: 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)