JSTL遍历复杂Map对象

问:如何用JSTL遍历一个复杂的Map?

Map<Integer,ArrayList<Object>> myMap = new LinkedHashMap<Integer,ArrayList<Object>>();

 

 

答:

 

    如果是basic example

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:forEach items="${map}" var="entry">
    Key = ${entry.key}, value = ${entry.value}<br>
<c:forEach>

 

    借鉴以上的例子,则可以发现正确的解答应该为

 

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:forEach items="${map}" var="entry">
    Key = ${entry.key}, values = 
    <c:forEach items="${entry.value}" var="item" varStatus="loop">
        ${item} ${!loop.last ? ', ' : ''}
    </c:forEach><br>
<c:forEach>

 

 

 

 

 

 

你可能感兴趣的:(map java jstl)