我在通过 struts 访问属性时遇到问题。我想知道是否有对 struts 更有经验的人可以给我一些指导。
Java 类大致设置如下:
public abstract class parent{
protected Integer id;
public Integer getId(){
return this.id;
}
}
public class child extends parent{
// stuff
}
子级是一个动作类中的列表,并设置了 getter:
private List<child> childList;
这是我在前端的代码,试图获取
id
属性:
<s:iterator value="childList" status="cStatus">
<s:property value='id' />
</s:iterator>
但是,什么也没有出现。我已经从子类中获取了其他成员,所以我假设我在抽象类中获取的父成员存在问题?
更新:
我尝试在
jsp
中获取抽象类中的另一个属性,并且效果很好。我抢到的另一处财产是creationDate
。我还向 id
getter 添加了断点,它可以正常访问并返回非空值。这是父级的更详细实现,其中包含 hibernate
注释:
@MappedSuperclass
public abstract class parent{
protected Integer id;
protected Date creationDate;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@DocumentId
public Integer getId() {
return this.id;
}
protected void setId(Integer id) {
this.id = id;
}
@Column(updatable=false, nullable=false)
@Temporal(TemporalType.TIMESTAMP)
public Date getCreationDate() {
return this.creationDate;
}
@SuppressWarnings("unused")
private void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
}
问题出在
private List<child> childList;
需要
private List<child> childList = new ArrayList<>();
public List<child> getChildList(){
return childList;
}
在 JSP 中
<s:iterator value="childList" status="cStatus">
<s:property value="id" />
</s:iterator>