急急急,在线等!!!!!!!!!!!!

yzj926 2007-07-16 03:31:52
List<EinfoFund> result;
result=projectService.findFieldToExport(ee.getField(),Project id);
请问一下:我查询的结果放在这个RESULT里面,怎么才能取到这里面的每一个变量的值啊,比如说这结果里面有address,markerip,no之类的
...全文
209 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
KingNE 2007-07-16
  • 打赏
  • 举报
回复
up
yzj926 2007-07-16
  • 打赏
  • 举报
回复
是ARRAYLIST啊,你这样写的EinfoFund ef = (EinfoFund) result[i];result[i]显然是错的呢
lingar 2007-07-16
  • 打赏
  • 举报
回复
你可以端点执行 到 result=projectService.findFieldToExport(ee.getField(),Project id);
看看list里面包含的是ArrayList还是直接是对象
result=projectService.findFieldToExport(ee.getField(),ProjectClass.einfoFund, id);
for(int i=0;i<result.size();i++){
EinfoFund ef = (EinfoFund) result[i];
System.out.println(ef.getAddress());
}

yzj926 2007-07-16
  • 打赏
  • 举报
回复
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
ExportExcel ee = (ExportExcel) command;
List<EinfoFund> result;
Long id = Long.parseLong(request.getParameter("id"));
result=projectService.findFieldToExport(ee.getField(),ProjectClass.einfoFund, id);
for(Iterator it=result.iterator();it.hasNext();){
EinfoFund ef = (EinfoFund) it.next();
System.out.println(ef.getAddress());
}
ExcelDataWriter ew = new ExcelDataWriter();
HashMap<String, Object> model = new HashMap<String, Object>();
String returnUrl = request.getContextPath() + "/";
addNavLink("返回", returnUrl, LinkType.Hyperlink, model);
return new ModelAndView(getSuccessView(), model);
}

这上面是控制器里的代码,下面是查询的代码:
public List<EinfoFund> findFieldToExport(String[] props,ProjectClass projectClass, Long id) {
StringBuilder sb = new StringBuilder("select ");
for (int i = 0; i < props.length; i++) {
String prop = props[i];
if(i>0){
sb.append(",");
}
sb.append(prop);
}
sb.append(" from ").append(projectClass.getEntityClass().getName()).append(" where ");
sb.append("project_id=").append(id);
System.out.println(sb.toString());
return einfoFundDao.findByHql(sb.toString());
}
lingar 2007-07-16
  • 打赏
  • 举报
回复
代码完整点
yzj926 2007-07-16
  • 打赏
  • 举报
回复
是把每条记录都封装到EinfoFund对象中了,怎样才能让它类型匹配呢,我要从结果集中取值出来
lingar 2007-07-16
  • 打赏
  • 举报
回复
projectService.findFieldToExport(ee.getField(),Project id);
你这个方法中有把每条记录都封装到EinfoFund对象中呢
如果没有 (EinfoFund)it.next();肯定是类型不匹配阿
yzj926 2007-07-16
  • 打赏
  • 举报
回复
大家帮忙看下啊谢谢
yzj926 2007-07-16
  • 打赏
  • 举报
回复
不行啊,大哥
java.lang.ClassCastException: [Ljava.lang.Object;
at com.wp.apply.corp.web.controller.EinfoFundExportController.onSubmit(EinfoFundExportController.java:26)
EinfoFund ef = (EinfoFund)it.next();
这一行它报错
masse 2007-07-16
  • 打赏
  • 举报
回复
遍历啊
jdk1.4的写法:

for(Iterator it=result.iterator();it.hasNext();){
EinfoFund ef = (EinfoFund)it.next();
System.out.println(ef.getAddress()); // 调用你自己的getter
}
overflier 2007-07-16
  • 打赏
  • 举报
回复
我不太明白楼主的意思,能否说的明白一些?

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧