Springboot上传集合,集合超过256直接下标越界
- 解决方法一 单个controller生效
- 解决方法二 全局controller生效
org.springframework.beans.InvalidPropertyException: Invalid property 'files[256]' of bean class [analysis.vo.wcase.InsertCase]: Invalid list index in property path 'files[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
解决方法一 单个controller生效
在当前controller,添加如下配置(只有当前controller才会生效)
@InitBinder public void initBinder(WebDataBinder binder) { binder.setAutoGrowNestedPaths(true);//设置处理嵌套属性binder.setAutoGrowCollectionLimit(5000); }
解决方法二 全局controller生效
创建一个全局配置类
@Configuration
public class ListSizeConfig {@Autowiredpublic ListSizeConfig(RequestMappingHandlerAdapter requestMappingHandlerAdapter) {requestMappingHandlerAdapter.setWebBindingInitializer(new MyWebBindingInitializer());}/*** 配置请求集合上限数量*/public static class MyWebBindingInitializer extends ConfigurableWebBindingInitializer {@Overridepublic void initBinder(WebDataBinder binder) {super.initBinder(binder);binder.setAutoGrowNestedPaths(true);//配置集合上限数量,配置接收list的长度5000binder.setAutoGrowCollectionLimit(5000);}}
}