出现的场景是: 前端 提交一个form 里面包含 一个list里面的对象有 427 个
注意其中的一个类 DataBinder.java:859
进入后看到
public static final int DEFAULT_AUTO_GROW_COLLECTION_LIMIT = 256;
*/
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;
/**
* We'll create a lot of DataBinder instances: Let's use a static logger.
*/
protected static final Log logger = LogFactory.getLog(DataBinder.class);
private static Class<?> javaUtilOptionalClass = null;
static {
try {
javaUtilOptionalClass =
ClassUtils.forName("java.util.Optional", DataBinder.class.getClassLoader());
}
catch (ClassNotFoundException ex) {
// Java 8 not available - Optional references simply not supported then.
解决办法
1)修改业务,不允许一次提交超过256条数据
2)在需要的Action中添加InitBinder方法。如果所有Action都需要添加……不仅工作量很大,而且代码冗余很难看
//在当前Controller中加 或者 在 BaseController 中加入
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
}
//或者 采用 @ControllerAdvice
package cn.mwee.wpos.report.aspect;
import cn.mwee.wpos.common.config.AppConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import javax.servlet.http.HttpServletRequest;
/**
* Created by luob on 2017/9/21.
*/
@ControllerAdvice
public class CollectionGrowLimitAdvice {
@Autowired
private AppConfig appConfig;
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAutoGrowCollectionLimit(appConfig.getCollectionGrowLimit());
}
}
3)增加一个WebBindingInitializer类,并在xml中配置。推荐大笑(如果你不知道改哪个xml文件,先好好学习一下SpringMVC吧奋斗)
public class DataBindingInitializer implements WebBindingInitializer {
@Override
public void initBinder(WebDataBinder binder, WebRequest request) {
binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
}
}
spring-bean.xml
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="xxx.DataBindingInitializer"/>
</property>
</bean>
- 大小: 83 KB
分享到:
相关推荐
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder 继承并重写LinearLayoutManager.onLayoutChildren()方法 class WrappedLinearLayoutManager : ...
java.lang.ArrayIndexOutOfBoundsException: 128 at android.content.res.StringBlock.getShort(StringBlock.java:231) at android.content.res.StringBlock.getString( StringBlock.java:91) at android.content...
java 索引越界异常(IndexOutOfBoundsException) java 索引越界异常(IndexOutOfBoundsException)
JAVA面试题集 基础知识: 1.C++或Java中的异常处理机制的简单原理和应用。 当JAVA程序违反了JAVA的语义规则时,JAVA虚拟机就会将发生的错误表示为一个异常。...所有的异常都是java.lang.Thowable 的子类。
java面试题集 1.C++或Java中的异常处理机制的简单原理和应用。 当JAVA程序违反了JAVA的语义规则时,JAVA虚拟机就会将发生的错误表示为一个异常。违反语义规则包括2种情况...所有的异常都是java.lang.Thowable的子类。
rectclerView出现java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 2(offset:2) 解决方案:原因就是在清除数据源的时候没有及时notify,需要及时更新list,否则就会报这个错误. ...
堆栈跟踪:异常:IndexOutOfBoundsException消息:索引:0,大小:0跟踪:java.util.ArrayList.rangeCheck(未知源)java.util.ArrayList.get(未知源)org.spoutcraft.launcher.skin.NewsComponent.setupArticles ...
基础知识:1.C++或Java中的异常处理机制的简单原理和应用。当JAVA程序违反了JAVA的语义规则时,JAVA虚拟机就会将发生的错误表示为一个异常。违反语义规则包括2种情况。...所有的异常都是java.lang.Thowable的子类。
1. Java 中的异常处理机制的简单原理和应用。 当 Java 程序远反了 Java 的语义规则时,Java 虚拟机就会将发生的错误表示为 一个异常。远反语义规则包括 2 种情况。...常都是 java.lang.Thowable 的子类。
1.Java中的异常处理机制的简单原理和应用。 当JAVA程序违反了JAVA的语义规则时,JAVA虚拟机就会将发生的错误表示为一个异常。违反语义规则包括2种情况。...所有的异常都是java.lang.Thowable的子类。
java面试题集 1.C++或Java中的异常处理机制的简单原理和应用。 当JAVA程序违反了JAVA的语义规则时,JAVA虚拟机就会将发生的错误表示为一个异常。违反语义规则包括2种情况...所有的异常都是java.lang.Thowable的子类。
当Java程序违反了Java的语义规则时,Java虚拟机就会将发生的错误表示为一个异常。违反语义规则包括2种情况。一种是Java类库内置的语义检查。例如数组下标越界,会引发...所有的异常都是java.lang.Thowable的子类。
所有的异常都是java.lang.Thowable的子类。 2. Java的接口和C++的虚类的相同和不同处。 由 于Java不支持多继承,而有可能某个类或对象要使用分别在几个类或对象里面的方法或属性,现有的单继承机制就不能满足...
所有的异常都是java.lang.Thowable的子类。 2. Java的接口和C++的虚类的相同和不同处。 由于Java不支持多继承,而有可能某个类或对象要使用分别在几个类或对象里面的方法或属性,现有的单继承机制就不能满足要求。...
所有的异常都是java.lang.Thowable的子类。 2. Java的接口和C++的虚类的相同和不同处。 由于Java不支持多继承,而有可能某个类或对象要使用分别在几个类或对象里面的方法或属性,现有的单继承机制就不能满足要求。...
NULL 博文链接:https://liuzidong.iteye.com/blog/1071677
所有的异常都是java.lang.Thowable的子类。 2. Java的接口和C++的虚类的相同和不同处。 由于Java不支持多继承,而有可能某个类或对象要使用分别在几个类或对象里面的方法或属性,现有的单继承机制就不能满足要求。与...
所有的异常都是java.lang.Thowable的子类。 2. Java的接口和C++的虚类的相同和不同处。 由于Java不支持多继承,而有可能某个类或对象要使用分别在几个类或对象里面的方法或属性,现有的单继承机制就不能满足要求...
如果插入不正确的索引,则会引发java.lang.IndexOutOfBoundsException 。 RestPersona是允许您进行 Rest 调用的端点。 在getPersona 中,如果返回空值,则会通过调用EJB提供的服务引发MyException异常。 此异常...
If the index is out of bounds, the method readValue(int [ ] a, int k) should throw an IndexOutOfBoundsException. The main program should catch the exception and display the message "out of bounds".