SpringMVC框架前端传递List限制大小256问题
来源:互联网 发布:个人如何使用阿里云 编辑:程序博客网 时间:2024/04/30 08:59
SpringMVC前端传递List到后台限制256问题
在做项目的时候,出现了一个问题,有个需求需要把前台长度很长的数组传递到后台进行保存,自己做的时候只是用了几十条数据进行测试,没啥问题,后面测试人员说当数据998条时报错了,数组下标越界
溯源了下Spring的代码,找到了DataBinder,先解释下DataBinder类的作用,见链接
http://docs.spring.io/spring/docs/1.2.x/api/org/springframework/validation/DataBinder.html
其中有一句
Binder that allows for binding property values to a target object. The binding process can be customized through specifying allowed fields, required fields, and custom editors. Note that there are potential security implications in failing to set an array of allowed fields. In the case of HTTP form POST data for example, malicious clients can attempt to subvert an application by supplying values for fields or properties that do not exist on the form. In some cases this could lead to illegal data being set on command objects or their nested objects. For this reason, it is highly recommended to specify the allowedFields property on the DataBinder.
大概意思是前台的Form 元素绑定到 后台的JaveBean对象,做的一个映射,但是这个映射的List长度不可以超过256
反编译的源码如下:
解决如下:重set下autoGrowCollectionLimit,当做绑定的时候set为1024或者更大
/** * 由于Spring在接受前台传入的List时,就会出现256的IndexOutOfBoundsException异常 * 设置setAutoGrowCollectionLimit为1024 * @param binder * @see [类、类#方法、类#成员] */ @InitBinder public void initListBinder(WebDataBinder binder) { // 设置需要包裹的元素个数,默认为256 binder.setAutoGrowCollectionLimit(1024); }
这段代码我发现在项目在解决框架缺陷的时候已经在baseAction里重写了这个方法,在其他Action里是继承了baseAction,在开发环境里测试时没有问题的,但在测试环境里就不生效了,最后想到了两个解决方案,
1.直接在自己的Action在去重写上面的方法
2.在前台把数组转换成Json串,传到后台把Json串转换成集合
方案一:其实上面的那段代码写在baseAction里就是为了在其他的Action里不用重写了,但是在测试环境不生效,很郁闷,只有先这样子了
方案二: JSON.stringifier(myObject); 但传到后台是报错,应为存在特殊字符
方案三:开发环境可以,测试环境不可以,会不会是其他问题,于是又让部署人员清除下部署包缓存,但是还是没用,可能就是两个环境存在差异吧
阅读全文
0 0
- SpringMVC框架前端传递List限制大小256问题
- SpringMVC框架前端传递List限制大小256问题
- springmvc封装list个数限制问题
- spring-mvc限制前端传递list参数的长度为256
- 【Android】intent传递数据时,数据大小的限制问题
- 【Android】intent传递数据时,数据大小的限制问题
- 江湖问题研究-- intent传递有没有大小限制,是多少?
- springmvc传递list对象
- springMVC传递LIst
- post大小限制问题
- springmvc ajax 传递list参数
- postman传递list到springmvc
- 前端限制上传文件的大小
- intent传递有没有大小限制,是多少?
- intent传递有没有大小限制,是多少?
- SpringMVC提交参数绑定list时,默认配置如果list大小超过256,就会报错
- SpringMVC提交参数绑定list时,默认配置如果list大小超过256,就会报错
- SpringMVC参数传递方式list,map
- Spring Cloud Swagger(接口管理)
- linux基础操作命令
- 大数据系统与大规模数据分析 之 作业二
- 【Python初学笔记】set()字符串后为什么消除重复元素?
- java基础内容每日笔记_day01
- SpringMVC框架前端传递List限制大小256问题
- CentOS7 编译安装Memcached、设置自启动、php7编译安装Memcached
- Spring Cloud Zuul (服务网关)
- 百度地图 Android 设置 InfoWindow 不同缩放级别均能居中(自定义偏移量)
- C的旅程系列之第一个C程序
- springmvc文件上传下载简单实现案例(ssm框架使用)
- C# 中配置文件的使用
- 909422229_Hibernate第二节数据持久
- 利用Python输出斐波拉契数列