今天在处理程序的时候,偶然间发现了这个问题,当页面的list过大(256)时,提交到后台就会报错,于是乎查询了好多资料,尝试着去解决这个问题,但是我试了网上说的两种方法,貌似都没管用,后来重写了DataBinder的类才算得以解决!
问题如下:
因为每个controller都有继承的父类,所以调查源码得知,框架限制了list传往后台的大小给了限制,只摘取了最关键的代码,源码如下:
public class DataBinder implements PropertyEditorRegistry, TypeConverter {
/** Default object name used for binding: "target" */
public static final String DEFAULT_OBJECT_NAME = "target";
/** Default limit for array and collection growing: 256 */
public static final int DEFAULT_AUTO_GROW_COLLECTION_LIMIT = 256;
private int autoGrowCollectionLimit = DEFAULT_AUTO_GROW_COLLECTION_LIMIT;
/**
* Specify the limit for array and collection auto-growing.
* <p>Default is 256, preventing OutOfMemoryErrors in case of large indexes.
* Raise this limit if your auto-growing needs are unusually high.
*/
public void setAutoGrowCollectionLimit(int autoGrowCollectionLimit) {
this.autoGrowCollectionLimit = autoGrowCollectionLimit;
}
/**
* Return the current limit for array and collection auto-growing.
*/
public int getAutoGrowCollectionLimit() {
return this.autoGrowCollectionLimit;
}
}
我试了网上说的两种方法(参考方法),都没其效果,不知道究竟问题出现在了哪里!还望知道朋友告诉我。我的做法是在项目下创建同样的目录,重写DataBinder的方法,修改限制大小,改为自己理想的值即可,这里我直接设置了10000,不知道会不会有别的问题。