springMVC框架提交参数list时,springmvc默认只能接收到255个数据,当你前台传的数据长度大于255位的时候就会报错
例如我在前台传输的solutionModelList的长度有364位,在chrome控制台可以看到
然后在后台接收
@RequestMapping("/saveFinance.json")@ResponseBodypublic AjaxObj saveFinance(List<SolutionModelEntity> solutionModelList) { }
- 1
- 2
- 3
- 4
报错
解决办法:在你的controller层加上初始化方法
//这个类初始化的时候会首先调用init方法@InitBinder //类初始化是调用的方法注解public void initBinder(WebDataBinder binder) { //给这个controller配置接收list的长度100000,仅在这个controller有效 binder.setAutoGrowCollectionLimit(100000); }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
但是这个方法之针对这样处理过的类有用,要想在整个项目下都定义长度,如下:
定义一个初始化类
public class myInitializer implements WebBindingInitializer { @Override public void initBinder(WebDataBinder binder) { binder.setAutoGrowCollectionLimit(100000); } } 然后在配置文件配置 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="webBindingInitializer"> <bean class="xxx.myInitializer"/> //class指myInitializer类 </property> </bean>
原博客地址:http://blog.csdn.net/csdnzhangtao5/article/details/53411649