列表页面需要分类显示,因此要对数据库查询出来的结果进行分组。贴代码:
action里的代码操作
List<ProjectInfo> projectInfoSingle = this.projectInfoService.getSubProjectInfoList(this.getOperatorId());
mapList = new HashMap<String,List<ProjectInfo>>();
String productName = null;
for(Iterator it = projectInfoSingle.iterator();it.hasNext();)
{
ProjectInfo projectInfo = (ProjectInfo)it.next();
productName = this.productFacade.getProductNameById(projectInfo.getProductTypeId());
if(mapList.containsKey(productName))
{ //如果已经存在这个数组,就放在这里
List<ProjectInfo> projectInfoList = mapList.get(productName);
projectInfoList.add(projectInfo);
}else
{
List<ProjectInfo> projectInfoList2 = new ArrayList<ProjectInfo>();
//重新声明一个数组list
projectInfoList2.add(projectInfo);
mapList.put(productName, projectInfoList2);
}
}
jsp页面的展现
<s:iterator value="mapList" id="p" status="rs">
<div class="tab-title">
<h2><s:property value="key" /></h2><!--<s:property value="#p.productTypeId"/> -->
</div>
<ul class="m-ul-list01">
<!-- 通过value取HashMap的每一个List, 开始迭代List -->
<s:iterator value="value" id="i" status="status">
<li><a href="#"><s:property value="#i.name"/></a></li>
</s:iterator>
</ul>
</s:iterator>