<form>
<input type='hidden' name='showColumnDto[0].id' value='599'>
<input type='hidden' name='showColumnDto[0].columnname' value='id'>
<input type='hidden' name='showColumnDto[0].name' value='id'>
<input type='hidden' name='showColumnDto[0].isshow' value='false'>
<input type='hidden' name='showColumnDto[0].index' value='1'>
...
<input type='hidden' name='showColumnDto[254].id' value='599'>
<input type='hidden' name='showColumnDto[254].columnname' value='id'>
<input type='hidden' name='showColumnDto[254].name' value='id'>
<input type='hidden' name='showColumnDto[254].isshow' value='false'>
<input type='hidden' name='showColumnDto[254].index' value='1'>
<input type='hidden' name='showColumnDto[255].id' value='599'>
<input type='hidden' name='showColumnDto[255].columnname' value='worktype'>
<input type='hidden' name='showColumnDto[255].name' value='售后'>
<input type='hidden' name='showColumnDto[255].isshow' value='false'>
<input type='hidden' name='showColumnDto[255].index' value='1'>
<input type='hidden' name='showColumnDto[256].id' value='599'>
<input type='hidden' name='showColumnDto[256].columnname' value='extraid'>
<input type='hidden' name='showColumnDto[256].name' value='jobs_1'>
<input type='hidden' name='showColumnDto[256].isshow' value='false'>
<input type='hidden' name='showColumnDto[256].index' value='1'>
</form>
问题描述:form表单数组个数小于等于256时正常,大于256时,springMVC Controller报错如下:
2015-3-10 20:44:26 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet dispatcher threw exception java.lang.IndexOutOfBoundsException: Index: 256, Size: 256 at java.util.ArrayList.RangeCheck(ArrayList.java:547)
感觉应该程序没错误,只是某个地方有默认设置。后经多方查证,是因为springmvc默认只支持256个对象映射,加入以下代码即可解决:
@InitBinder
public void initListBinder(WebDataBinder binder) {
// 设置需要包裹的元素个数,默认为256
binder.setAutoGrowCollectionLimit(5000);
}