我是春天新手。我有一个列表,其中包含嵌套的LinkedHashMaps。
LinkedHashMap<String, String> columnMap = new LinkedHashMap<String, String>();
LinkedHashMap<String, LinkedHashMap<String, String>> columnGroupMap = new LinkedHashMap<String, LinkedHashMap<String, String>>();
LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>> rowMap = new LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>>();
List<LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>>> rowList = new ArrayList<LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>>>();
columnMap.put("row1xcolumn1", "value1");
columnGroupMap.put("summary", columnMap);
rowMap.put("Row1", columnGroupMap);
:
columnMap = new LinkedHashMap<String, String>();
columnMap.put("row2xcolumn1", "value1");
columnGroupMap.put("summary", columnMap);
rowMap.put("Row2", columnGroupMap);
:
rowList.add(rowMap);
model.addAttribute("rowList", rowList);
我已将值存储在哈希映射中,最后将rowMap添加到rowList中。我需要在视图中打印columnMap的键值。以下是我查看的代码:
<c:forEach var="rowMap" items="${rowList}" varStatus="rowList">
<tr>
<c:forEach items="${rowMap['summary']}" var="rowColumnMap" varStatus="rowColumnMap">
<c:forEach items="${rowColumnMap}" var="fieldCol" varStatus="columnMap">
<th class="tableHeaderCellSummary">
${fieldCol.key} = ${fieldCol.value}
</th>
</c:forEach>
</c:forEach>
</tr>
</c:forEach>
我无法看到页面中生成的行。请帮我定义视图。
还有一种方法可以直接获取columnMap值而无需迭代吗?
答案 0 :(得分:0)
我没有传递rowList,而是通过了rowMap,让它工作了! 以下是控制器代码的更改:
//List<LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>>> rowList = new ArrayList<LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, String>>>>();
//model.addAttribute("rowList", rowList);
model.addAttribute("rowMap", rowMap);
以下是视图代码:
<c:forEach var="rowMapVar" items="${rowMap}">
<tr>
<td class="tableCell" style="text-align: left;" nowrap> New Test Case </td>
<c:forEach items="${rowMapVar.value['summary']}" var="hSummaryTC">
<td class="tableCell" style="text-align: center;">${hSummaryTC.value}</td>
</c:forEach>
</tr>