如何在 JSP 页面中获取多对一关系?我试过了
<s:property value="group.division.name" />
但 JSP 上没有出现任何数据。
Group
可以属于Division
一个。
public class Group implements java.io.Serializable {
..
private Division division;
..
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "div_id", nullable = false)
public Division getDivision() {
return this.division;
}
public void setDivision(Division division) {
this.division = division;
}
}
和
public class Division implements java.io.Serializable {
...
private String name;
private Set<Group> groups = new HashSet<Group>(0);
@Column(name = "name", nullable = false, length = 50)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "division")
public Set<Group> getGroups() {
return this.groups;
}
public void setGroups(Set<Group> groups) {
this.groups = groups;
}
}