简体   繁体   中英

jstl iterator map and list

The follow code is not working:

    <c:forEach items="${orderNumByDepartment}" var="map2">
        <c:forEach items="${map2.value }" var="foodName2foodNum">

            <tr>
                    <td>${map2.key }</td>
                    <td>${foodName2foodNum.key }</td>
                    <td>${foodName2foodNum.value }</td>
            </tr>

        </c:forEach>
    </c:forEach>

orderNumByDepartment is Map<String, List<Map<String, Integer>>> type.

Can you tell me why I can not get the second and third value(foodName2foodNum.key/foodName2foodNum.value)

我认为Map<String, List<Map<String, Integer>>>应该是Map<String, Map<String, Integer>> ,因为你想foodName2foodNum是一个地图,而不是一个地图列表, map2则是类型Map.Entry<String, Map<String, Integer>>

foodName2foodNum is the whole map rather than a single map entry, so does not have a key and value. If you want the String keys and the Integer values from the Map entries, try creating another c:forEach loop inside the map2.value loop. Eg

<c:forEach items="${foodName2foodNum}" var="thirdLoopVar">
  <p>${thirdLoopVar.key}</p>
  <p>${thirdLoopVar.value}</p>
</c:forEach>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM