gpt4 book ai didi

java - Spring MVC 中索引越界

转载 作者:行者123 更新时间:2023-11-30 03:11:30 26 4
gpt4 key购买 nike

我有一个 bean AgreegateBean,我将其用作传输对象。 bean 的类定义如下 -

Class AgreegateBean {

private SomeOtherBean bean;
private List<Person> someList;

// getters and setters
}

我正在带有 ModelAttribute 注释的 Spring Controller 中使用这个 bean。对于 JSP,我有 JSTL。我已经用这样的字段填充了 JSP。

 <input type="text" name="someList[0].name" />
<input type="text" name="someList[0].surName" />

当我提交表单时,我收到 java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

org.springframework.beans.InvalidPropertyException: Invalid property 'someList[0]' of bean class [com.form.bean.AgreegateBean]: Index of out of bounds in property path 'someList[0]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

最佳答案

这是因为检索到的 List<Person> someList; 中没有元素

之前检查一下:

<c:if test="${someList != null}">
<input type="text" name="someList[0].name" />
<input type="text" name="someList[0].surName" />
</c:if>

关于java - Spring MVC 中索引越界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33544279/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com