【发布时间】:2016-05-02 21:01:02
【问题描述】:
对此进行排序有点困难。在我的 JSP 页面中,我有一个表格,其中显示了 x 行数和 3 列。在我的 Java bean 中,我将其声明为:
private ArrayList<Map<String, String>> issueClient = new ArrayList<>();
private ArrayList<Map<String, String>> issueR2 = new ArrayList<>();
我通过 MVC 获取我的值并将它们放入 Map 中:
if (crs != null && crs.size() > 0) {
try {
while (crs.next()) {
HashMap<String, String> tmpPart = new HashMap<>();
tmpPart.put("part", crs.getString("part"));
tmpPart.put("type", crs.getString("part_type"));
tmpPart.put("id_issue", crs.getString("id_part"));
tmpPart.put("issue", crs.getString("part_name"));
repairPartAddNew.addIssueClientMap(tmpPart);
}
} catch (Exception e) {
....
}
} else {
....
}
repairPartAddNew 是对包含上述 ArrayList 映射的 Java Bean 的引用。在我的 JSP 中,我已经开始构建以下内容:
<c:if test="${repairPartAddNew.issueClient != null}">
<c:set var="loopValue" value="1" scope="page" />
<c:forEach var="issueClient" items="${repairPartAddNew.issueClient}" varStatus="loop">
<c:forEach var="map" items="${issueClient}">
<tr>
<td>
<form:select disabled="disabled" multiple="false" id="clientReportIssuePart${loopValue}" class="form-control input-sm" name="clientReportIssuePart" path="clientReportIssuePart" onchange="getPartSubtypes(this.value,$(this).parent().next().find('select').attr('id'));">
<form:option value="${map.value}">${map.value}</form:option>
<form:options items="${descriptionParts}" itemValue="value" itemLabel="name"/>
</form:select>
</td>
<td>
<form:select disabled="disabled" multiple="false" class="form-control input-sm" id="clientPartType${loopValue}" name="clientPartType" path="clientPartType" onchange="getRepairPartIssue(this.value,$(this).parent().next().find('select').attr('id'),$(this).parent().prev().find('select').val());">
<form:option value="${map.value}">${map.value}</form:option>
</form:select>
</td>
<td>
<form:select disabled="disabled" multiple="false" class="form-control input-sm" id="clientRepair${loopValue}" name="clientReportIssuePartId" path="clientReportIssuePartId">
</form:select>
</td>
</tr>
</c:forEach>
<c:set var="loopValue" value="${loopValue + 1}" scope="page"/>
</c:forEach>
</c:if>
我最终得到了数据结构中的各种可憎,包括http://prnt.sc/azjlgp
似乎遍历 Array 和 Map 会产生重复的行。在此示例中,应该只有 2 个表格行。
非常感谢任何帮助。
【问题讨论】:
-
如果列表中的每个地图都应该是一行,为什么你有两个嵌套的forEach?你到底为什么要用地图来表示你的模型,而不是对象,用命名的、类型化的属性?
-
@JBNizet 你说得对,我没有从正确的角度看它。
标签: java dictionary arraylist jstl