转发我在2008年写在163的博客<Struts2中Iterator的用法>

以下内容属转载:

Action 中大概是这样:

import java.util.Iterator;

import java.util.List;

import com.mingda.model.Chargecode_info;

import com.mingda.service.Timereport_infoService;

import com.opensymphony.xwork2.Preparable;

public class Timereport_infoAction implements Preparable{

private List timereport_infos;

private Timereport_info timereport_info;



this.service = service;

public String searchChargeCode(){ //页面上查询功能所调用的方法,结果返回的是每天的工作时间记录

timereportinfo_view = new LinkedHashMap>();

把每天的日期(String类型)作为LinkedHashMap的键。

List temp = this.service.searchByTrDateTime(tr_datetime,userid); //返回某一天的工作时间记录

.....

}

用图解的方式说明一下timereportinfo_view这个Map中数据的存放形式

/ [1]
——List{#a,#b
}

}

(map) \ ....





问题一:timereportinfo_view(LinkedHashMap类型的),而且timereportinfo_view嵌套了List,我需要的记录是存放在List当中的,那我在jsp页面中如何使用

答:


// 实际上ValueList中的值就是timereportinfo_view这个map的键。你可以去掉注释,页面上会打印出“键”。

//这个就是我想要得到的,和数据库表中相对应的字段




答:







问题三:在jsp页面上java代码部分用List存放了一些数据如何将List赋值给iterator,像这样:


....

.....

//do some thing




如果这么写

//do some thing

是肯定会报错的。


request.setAttribute("list", list); %>

//struts2官方文档中有iterator标签的例子,大家可以好好看看。




错误示例 :

//假设“ActionList”对应着action.java中已经定义的private List ActionList;并有get set 方法。

//do something

这里程序会报错,主要因为在内层中top所遍历的是当前的集合而且与同是当前集合中charge_code_id的有冲突。

解决方法:

很简单用,往下看:





Here we use the IteratorStatus determine every fourth row to insert an extra line break.




odd : boolean - returns true if the current iteration is odd


index : int - returns the index (0 based) of the current iteration


last : boolean - returns true if the iteration is on the last iteration


modulus(operand : int) : int - returns the current count (1 based) modulo the given operand
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值