我在使用 jsp 槽列表/列表进行迭代时遇到问题。这是我的对象类,称为 Table:
public class Table{
private String name;
private List<String> columns;
private List<Row> rows;
... continuing with getters and setters nothing more here
}
在我的 Row 类中,我只有字符串(例如:字符串名称),没有列表,什么也没有。
目前我有一些List<Table>
我像这样迭代它:
<c:forEach var='table' items='${requestScope.tables}'>
<c:out value="{table.name}"></c:out>
</c:forEach>
只是为了测试..它只打印 {table.name}
x次(表列表中表对象的正确数量)。
我的最终目标是这样的(伪代码):
for each table in table list
print name
for each column in colum list
print column
end column list for
for each Row in row list
print Row.name
end row list for
end table list for
有人可以帮我解决语法问题吗?
最佳答案
<c:forEach var="table" items='${requestScope.tables}'>
<c:out value="${table.name}"></c:out>
<c:forEach var="column" items='${table.columns}'>
<c:out value="${column}"></c:out>
</c:forEach>
<c:forEach var="row" items='${table.rows}'>
<c:out value="${row.name}"></c:out>
</c:forEach>
</c:forEach>
关于java - Jsp遍历对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4729183/