1. 程式人生 > >springmvc封裝list個數限制問題

springmvc封裝list個數限制問題

spa 後臺 class hang ror databind ret work exce

提交一顆樹,三級區域個數大於1000個導致提交失敗!!!

org.springframework.beans.InvalidPropertyException: Invalid property ‘divisionList[1000]‘ of bean class [com.gome.bean.Presell]: Index of out of bounds in property path ‘divisionList[1000]‘; nested exception is java.lang.IndexOutOfBoundsException: Index: 1000, Size: 1000
    org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:
811) org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:554)

溯源了下Spring的代碼,找到了DataBinder,先解釋下DataBinder類的作用,見鏈接
http://docs.spring.io/spring/docs/1.2.x/api/org/springframework/validation/DataBinder.html
其中有一句

INFO: More than the maximum number of request parameters (GET plus POST) for a single request ([10,000]) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.
 Note: further occurrences of this error will be logged at DEBUG level.

解決如下:重set下autoGrowCollectionLimit,當做綁定的時候set為3000或者更大
在Controller重寫這個方法

/**
     * 由於Spring在接受前臺傳入的List時,就會出現256的IndexOutOfBoundsException異常
     * 設置setAutoGrowCollectionLimit為1024
     * @param binder
     * @see [類、類#方法、類#成員]
     */
    @InitBinder
    public void initListBinder(WebDataBinder binder)
    {
        
// 設置需要包裹的元素個數,默認為256 binder.setAutoGrowCollectionLimit(3000); }
 

或者不用表單提交

先轉換成json字符串到後臺 然後用jsonarray反序列和成集合對象也是可以的

原貼  https://blog.csdn.net/zgliang88/article/details/52780213

springmvc封裝list個數限制問題