Struts2 hibernate一对多关系 1323
我正在尝试使用 struts2 和 hibernate 一对多关系
//Activities
@Entity
@Table(name="ACTIVITIES")
@OneToMany(fetch = FetchType.EAGER, mappedBy = "activities" , targetEntity=Favorites.class, cascade=CascadeType.ALL )
public Set<Favorites> getFavorites() {
return favorites;
}
public void setFavorites(Set<Favorites> favorites) {
this.favorites = favorites;
}
@Id
@GeneratedValue
@Column(name="ACTIVITYID")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
//Favorites
@Entity
@Table(name="Favorites")
@ManyToOne(optional=false)
public Activities getActivities() {
return this.activities;
}
以及 jsp 中的其他字段
显示两个表“活动”和“收藏夹”的值:
<s:iterator value="activityList" id="activityList" status="activityStatus" <s:hidden id="activityList" name="activityList[%{#activityStatus.index}].id" />
<s:iterator value="favorites" var="fav" status="myStat">
<s:checkbox id="accFavorities" name="accFavorities"/></td>
<s:iterator>
但是当提交时,我从活动表中获取 id,而不是值收藏夹表(即复选框)。
在我的动作类中,
for (Activities al : activityList) {
for (Favorites ss : al.getFavorites()) {
System.out.println(ss.getCompany());
System.out.println(ss.getAccFavorities());
}
}
在 jsp 中,我尝试了下面类似的方法,在这种情况下,数据库本身的值不会出现
<s:iterator value="%{favorites}" id="fav" status="myStat">
<s:checkbox id="accFavorities" value="activityList[%{#activityStatus.index}].fav[%{#myStat.index}].accFavorities"/></td>
任何帮助,非常感谢。
谢谢
I am trying to display value from two table Activites and Favorites using struts2 and hibernate one-to-many relationship
//Activities
@Entity
@Table(name="ACTIVITIES")
@OneToMany(fetch = FetchType.EAGER, mappedBy = "activities" , targetEntity=Favorites.class, cascade=CascadeType.ALL )
public Set<Favorites> getFavorites() {
return favorites;
}
public void setFavorites(Set<Favorites> favorites) {
this.favorites = favorites;
}
@Id
@GeneratedValue
@Column(name="ACTIVITYID")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
//Favorites
@Entity
@Table(name="Favorites")
@ManyToOne(optional=false)
public Activities getActivities() {
return this.activities;
}
and other fields
In jsp:
<s:iterator value="activityList" id="activityList" status="activityStatus" <s:hidden id="activityList" name="activityList[%{#activityStatus.index}].id" />
<s:iterator value="favorites" var="fav" status="myStat">
<s:checkbox id="accFavorities" name="accFavorities"/></td>
<s:iterator>
but when submit i am getting id from activity table but not values favorites table which is the checkbox.
In my action class
for (Activities al : activityList) {
for (Favorites ss : al.getFavorites()) {
System.out.println(ss.getCompany());
System.out.println(ss.getAccFavorities());
}
}
In jsp I tried something like this below in that case the value from database itself is not comming
<s:iterator value="%{favorites}" id="fav" status="myStat">
<s:checkbox id="accFavorities" value="activityList[%{#activityStatus.index}].fav[%{#myStat.index}].accFavorities"/></td>
Any help is really appreciated.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须定义复选框,以便当浏览器提交表单时,参数名称与预期的 bean 结构相匹配。
也许您可以尝试 http://struts.apache.org/2.2.1/docs/struts-2-form-tags.html#Struts2FormTags-Struts2CheckboxTag
You have to define your checkbox so that when browser submits the form, the parameter names match the expected bean structure.
Maybe you could try the "key" attribute of as shown in http://struts.apache.org/2.2.1/docs/struts-2-form-tags.html#Struts2FormTags-Struts2CheckboxTag