我有一个名为 Menu 的对象。它有一个名为 voceMenuList 的字段,它是一个 Set
@Component
@Entity
@Table(name="menu")
@Configurable
public class Menu implements Serializable{
....
@OneToMany(mappedBy="menu", fetch=FetchType.EAGER)
private Set<VoceMenu> voceMenuList;
public Set<VoceMenu> getVoceMenuList() {
return voceMenuList;
}
public void setVoceMenuList(Set<VoceMenu> voceMenuList) {
this.voceMenuList = voceMenuList;
}
.....
}
我正在尝试构建一个表单来保存或更新菜单。我做了一些链接:
<form:form action="editMenu" method="post" commandName="menu">
......
<c:forEach items="${menu.voceMenuList}" varStatus="counter">
<form:input path="voceMenuList[${counter.index}].id" maxlength="11"/>
.....
但是,当我尝试保存对象菜单时,我收到此错误:
Invalid property 'voceMenuList[0]' of bean class [com.springgestioneerrori.model.Menu]: Cannot
get element with index 0 from Set of size 0,
accessed using property path 'voceMenuList[0]'
我处理的forEach
方式不正确