我用struts2在jsp中遍历了一个集合,集合中也有数据就是没法显示,如果用el表达式取对象
可以打印出来,但是取对象的属性就报错
先上代码
// action层
@Controller
public class NreportAction extends BaseAction
{
/**
* 内部审计S相关的封装
*/
@Resource
private NreportService nreportService; // 内审service
private List nreportList;
private Nreport nreport;
public NreportAction(){
System.out.println("进来了");
}
// 内审填报页面
public String addUI(){
System.out.println("时空裂缝");
try {
// System.out.println("1.先查出上一年没有完成的任务");
// System.out.println("2.查询出纪检监察室下发状态 , 如果下发了,就显示一条记录,让下级部门填写");
nreportList = nreportService.findNotDoPro();
if(nreportList!=null && nreportList.size()>0){
System.out.println("上一年未完成的项目有"+nreportList.size()+"个");
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return "reportUI";
}
DAO层
public class NreportDaoImpl extends BaseDaoImpl implements NreportDao
{
@Override
public List<Nreport> findNotDoPro() {
Calendar c=new GregorianCalendar();//新建日期对象 int year=c.get(Calendar.YEAR);//获取年份 int month=c.get(Calendar.MONTH);/
// 获取当前年份
int year=c.get(Calendar.YEAR);
// sql语句 select proid from record where state=1 and (year like '%2015%')
// 从【记录表】查询 出上一年没有完成的记录,然后根据记录从【内部表】查出项目的List
List list = getSession().createSQLQuery(
"select proid from record where state=0 and deptType = '内部审计' and (year like \'%" + String.valueOf(year-1) + "%\')").list();
// 遍历List然后根据这个id来去查找林外一张表
String sql = "select * from nreport where nid in(";
for(int i=0;i<list.size();i++){
// sql = "where id in(1,2,3)";
// 如果当前获取的这个id不是最后一个id,那么加上‘,’
if(list.get(i)!= list.get(list.size()-1)){
sql+=list.get(i)+",";
}else{
sql+=list.get(i)+")";
}
}
System.out.println(sql+"看看sql长啥样");
// 从【内部表】查出未完成项目的List
List<Nreport> list2= getSession().createSQLQuery(sql).list();
return list2;
}
}
jsp
<form action="" method="post" enctype="multipart/form-data">
<table width="100%" border="0">
<tr class="t_tit">
<td width="40" align="center">序号</td>
<td width="80" align="center">项目名称</td>
<td width="80" align="center">审计类型</td>
<td width="40" align="center">送审金额</td>
<td width="40" align="center">预计审计费</td>
<td width="160" align="center">预计审计时间</td>
<td width="140" align="center">经费来源</td>
<td width="100" align="center">资金性质</td>
<td width="60" align="center">状态</td>
<td width="60" align="center">备注</td>
<td width="60" align="center">删除</td>
</tr>
<!-- 如果有上一年的已经启动但是没有完成的计划也显示在这里 -->
<s:iterator value="nreportList" status="st">
${nreportList[0] }
<s:if test="nreportList!=null">
<tr <s:if test="#st.odd">bgcolor="f8f8f8"</s:if> >
<td align="center"><s:property value="nid"/></td>
<td align="center"><s:property value="proname"/></td>
<td align="center"><s:property value="audittype"/></td>
<td align="center"><s:property value="ssmoney"/></td>
<td align="center"><s:property value="expeauditmoney"/></td>
<td align="center"><s:property value="expeaudittime"/></td>
<td align="center"><s:property value="moneyfrom"/></td>
<td align="center"><s:property value="moneyfunds"/></td>
<td align="center"><s:property value="state"/></td>
<td align="center"><s:property value="memo"/></td>
</tr></s:if>
<s:else>没数据?</s:else>
</s:iterator>
如果我 我jsp中写成上面这样 ${nreportList[0] } 就会输出toString格式的对象 [Ljava.lang.Object;@20d77d7d
如果写成 ${nreportList[0].getNid }就报错
错误信息:
十一月 17, 2016 5:09:16 下午 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NumberFormatException: For input string: "getNid"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:161)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:45)
... ...
页面显示出来表格了,是迭代出来的就是没有数据,都是空的格子
![图片说明](https://img-ask.csdn.net/upload/201611/17/1479374227_31350.jpg)
求大神指导怎么才能迭代出来数据???
没有C币 , 下次有了一定加倍赏。。。