日期:2014-05-18  浏览次数:20850 次

List集合取值问题
Action()方法
List list= service.queryApplySta(queryApplyStatusDto);  //queryApplyStatusDto给sql传入的参数

queryApplySta()方法
  QueryApplyDao dao = (QueryApplyDao) context.getBean("queryApplyDao");
  List<QueryApplyStatusDto> list = dao.queryApplySta(queryApplyStatusDto);
  return list

queryApplySta()方法中就学了和数据库交互取值后直接return

其中QueryApplyDao是实体类,例如包含 name、address、email
我要在Action()中拿到list中name的值,我该怎么遍历。
新手求教
list List Action 遍历

------解决方案--------------------

for(QueryApplyStatusDto obj : list) {
obj.getName()
}

------解决方案--------------------
List<QueryApplyStatusDto> queryList = (QueryApplyStatusDto)service.....

------解决方案--------------------
哥们不懂强制类型转换吗?,如果你没有指定list的泛型,那么默认是object类型的,别用foreach的方法,用
for(int1=0;i<list.size(),i++){
     dto d = (dto)list.get(i);
     d.getName();
}
------解决方案--------------------
for(int1=0;i<list.size(),i++){
      QueryApplyStatusDto dto = (QueryApplyStatusDto)list.get(i);
      System.out.println(dto.getName());
 } 
------解决方案--------------------
楼主这么写试试

for(int i=0;i<list.size(),i++){
      QueryApplyStatusDto dto = (QueryApplyStatusDto)list.get(i);
      System.out.println(dto.getName());
 }