这是DAO实现层方法: (其中2个参数是分页)
public List<TDMonopolizeManagerApp> findAllCollect(int pageNo, int pageSize) {
if (pageNo < 1)
{
return null;
}
int offset = (pageNo - 1) * pageSize;
return findByPage("select station,town,count(distinct village),count(distinct team),count(name),sum(applyPlantArea),sum(gmv) from TDMonopolizeManagerApp group by station,town",offset,pageSize);}
-------------------------------------------------------------------------------------
然后我再Servlet这样做的:
List list = managerAppService.findAllCollect(pageNo);
request.setAttribute("appCollect", list);
-------------------------------------------------------------------------
在jsp页面:
<logic:iterate id="ac" name="appCollect">
<tr>
<td>${ac.id }</td>
<td>${ac.station }</td>
<td>${ac.town}</td>
<td>${ac.village }</td>
<td>${ac.team }</td>
<td>${ac.name }</td>
<td>${ac.applyPlantArea }</td>
<td>${ac.gmv }</td>
</tr>
</logic:iterate>运行是报了这样的错误:
The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.
public List<TDMonopolizeManagerApp> findAllCollect(int pageNo, int pageSize) {
if (pageNo < 1)
{
return null;
}
int offset = (pageNo - 1) * pageSize;
return findByPage("select station,town,count(distinct village),count(distinct team),count(name),sum(applyPlantArea),sum(gmv) from TDMonopolizeManagerApp group by station,town",offset,pageSize);}
-------------------------------------------------------------------------------------
然后我再Servlet这样做的:
List list = managerAppService.findAllCollect(pageNo);
request.setAttribute("appCollect", list);
-------------------------------------------------------------------------
在jsp页面:
<logic:iterate id="ac" name="appCollect">
<tr>
<td>${ac.id }</td>
<td>${ac.station }</td>
<td>${ac.town}</td>
<td>${ac.village }</td>
<td>${ac.team }</td>
<td>${ac.name }</td>
<td>${ac.applyPlantArea }</td>
<td>${ac.gmv }</td>
</tr>
</logic:iterate>运行是报了这样的错误:
The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.
有个人这样说:你这样查询所返回的结果集是集合类型封装数组 大概是:List <Object[]>
也就是说你在循环该结果集后所得到的是个数据
因此在页面显示时应该是:
<c:forEach items="${list}" var="obj">
第一列:${obj[0]}
第二列:${obj[1]}
</c:forEach>然后我修改了 还是抱这样的错误 唉。
这个方法的返回值不能应用泛型 List <TDMonopolizeManagerApp>
也就是说你调用findByPage方法的时候返回的list要迭代循环取值,然后重新赋值给一个新的BEAN(要在页面显示字段的BEAN),然后在页面再用循环标签去显示,跟具体的使用什么标签没有关系,对应显示的序号,用循环标签的indexId属性去控制,如果是jstl标签好象是varStatus,struts标签是indexId.