gpt4 book ai didi

java - 是否可以在 jSTL 中使用 foreach 同时迭代两个项目?

转载 作者:IT老高 更新时间:2023-10-28 13:54:31 24 4
gpt4 key购买 nike

我的模型中有两个项目,我想使用 jSTL foreach 同时迭代它们。如何使用正确的语法来实现这一点?

最佳答案

可以调用varStatus.index获取本轮迭代的索引,然后作为第二个列表的查找。

例如,如果您有两个列表 people.firstnamespeople.lastnames,您可以这样做:

<c:forEach var="p" items="${people.firstnames}" varStatus="status">
<tr>
<td>${p}</td>
<td>${people.lastnames[status.index]}</td>
</tr>
</c:forEach>

关于java - 是否可以在 jSTL 中使用 foreach 同时迭代两个项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4142631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com