1、Action类中:声明list,并给它set、get方法,然后在action逻辑处理方法中,将查询到的数据赋给list
private Tousu tousu = new Tousu();
private TousuService ts = new TousuService();
<span style="color:#ff0000;">private List<Tousu> tlist;</span>
public Tousu getTousu() {
return tousu;
}
public void setTousu(Tousu tousu) {
this.tousu = tousu;
}
<span style="color:#ff0000;">public List<Tousu> getTlist() {
return tlist;
}
public void setTlist(List<Tousu> tlist) {
this.tlist = tlist;
}</span>
@Override
public Tousu getModel() {
if(tousu == null){
tousu = new Tousu();
}
return tousu;
}
public String findAll(){
tlist = ts.findall();
//ServletActionContext.getRequest().setAttribute("tlist", tlist);
return "success";
}
2、前台页面显示:使用struts2的<s:iterator>遍历list
<s:iterator value="tlist">
<tr>
<td><s:property value="tid"/></td>
<td><s:property value="username"/></td>
<td><s:property value="number"/></td>
<td><s:property value="email"/></s></td>
<td><s:property value="theme" /></td>
<td><s:property value="reason"/></td>
<td>
<a href="${pageContext.request.contextPath }/tousuhandle.jsp?id=${tid}">受理</a>
</td>
</tr>
</s:iterator>