java 如何迭代jstl中的列表列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14737337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to iterate over a list of lists in jstl?
提问by blue-sky
I have List in this format :
我有这种格式的列表:
List<List<Obj>> l3 = new ArrayList<List<Obj>>();
Obj contains a method called getVal.
Obj 包含一个名为 getVal 的方法。
How can I output the value of getVal for each Obj ?
如何为每个 Obj 输出 getVal 的值?
I can iterate over a List using :
我可以使用以下方法遍历列表:
<c:forEach var="mylist" items="${mylist}">
<c:out value="${mylist.val}"></c:out>
</c:forEach>
But how do I get the values contained in a list of lists ?
但是如何获取列表列表中包含的值?
回答by Tomasz Nurkiewicz
Just like you would do it in Java - with nested loops:
就像您在 Java 中所做的一样 - 使用嵌套循环:
<c:forEach var="innerList" items="${mylist}">
<c:forEach var="obj" items="${innerList}">
<c:out value="${obj.val}"></c:out>
</c:forEach>
</c:forEach>