web页面struts2 用 iterator 输出多条数据库记录,但是只是重复输出最后一条记录
数据库中有多条不同的记录,但只重复输出了最后一条,新手上路,请不吝赐教action:privateList<Record>list=newArrayList<Record...
数据库中有多条不同的记录,但只重复输出了最后一条,新手上路,请不吝赐教
action:
private List<Record> list = new ArrayList<Record>();;
private Record record;
public List<Record> getList() {
return list;
}
public void setList(List<Record> list) {
this.list = list;
}
public void setRecord(Record record) {
this.record = record;
}
public Record getRecord() {
return this.record;
}
public String execute() {
HttpServletRequest request = ServletActionContext.getRequest();
String nianyue = request.getParameter("nianyue");
if(nianyue == null)
nianyue = Util.nianyue();
String hql = "select record from Record record where time > '" + nianyue + "'";
dao.RecordQueryDAO rqDAO = new dao.RecordQueryDAO();
List<?> list2 = rqDAO.dailyrecordquery(hql);
Iterator<?> it = list2.iterator();
float in=0,out=0,s=0;
while(it.hasNext()) {
record = new Record();
record = (Record)it.next();
list.add(record);//测试输出每个record对象,都是正确的
}
return "OK";
}
web
<s:iterator value="list" id="list">
<tr>
<td align="left"><s:property value="record.id"/></td>
<td align="left"><s:property value="record.type"/></td>
<td align="left"><s:property value="record.useage"/></td>
<td align="left"><s:property value="record.amount"/></td>
<td align="left"><s:property value="record.time"/></td>
<td align="left"><s:property value="record.note"/></td>
</tr>
</s:iterator> 展开
action:
private List<Record> list = new ArrayList<Record>();;
private Record record;
public List<Record> getList() {
return list;
}
public void setList(List<Record> list) {
this.list = list;
}
public void setRecord(Record record) {
this.record = record;
}
public Record getRecord() {
return this.record;
}
public String execute() {
HttpServletRequest request = ServletActionContext.getRequest();
String nianyue = request.getParameter("nianyue");
if(nianyue == null)
nianyue = Util.nianyue();
String hql = "select record from Record record where time > '" + nianyue + "'";
dao.RecordQueryDAO rqDAO = new dao.RecordQueryDAO();
List<?> list2 = rqDAO.dailyrecordquery(hql);
Iterator<?> it = list2.iterator();
float in=0,out=0,s=0;
while(it.hasNext()) {
record = new Record();
record = (Record)it.next();
list.add(record);//测试输出每个record对象,都是正确的
}
return "OK";
}
web
<s:iterator value="list" id="list">
<tr>
<td align="left"><s:property value="record.id"/></td>
<td align="left"><s:property value="record.type"/></td>
<td align="left"><s:property value="record.useage"/></td>
<td align="left"><s:property value="record.amount"/></td>
<td align="left"><s:property value="record.time"/></td>
<td align="left"><s:property value="record.note"/></td>
</tr>
</s:iterator> 展开
2个回答
2011-07-31
展开全部
因为你的List是全局的,把list在循环中定义就好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询