我有一个包含以下代码的 .jsp
页面:
<tbody>
<c:forEach items="${companies}" var="companies">
<tr>
<td>${companies.id}</td>
<td>${companies.name}</td>
<td>${companies.email}</td>
<td>${companies.countryId}</td>
<td>${companies.sendToIdes}</td>
<td>${companies.senderId}</td>
</tr>
</c:forEach>
</tbody>
和这段代码:
<tbody>
<c:forEach items="${countries}" var="countries">
<tr>
<td>${countries.id}</td>
<td>${countries.code}</td>
<td>${countries.name}</td>
<td>${countries.model}</td>
<td>${countries.hctaId}</td>
<td>${countries.certificate}</td>
<td>${countries.signature}</td>
</tr>
</c:forEach>
</tbody>
看到companies
有countryId
,countries
有id
,它们与这2个信息相关。
我需要在我的公司
中插入与id
和countryId
相关的countries.name
。
最佳答案
假设 countries
是一个按国家 ID(即 country.id
)索引的 map ,${countries[company. CountryId].name}
将引用公司表中的国家/地区名称。
(顺便说一下,我建议您在 c:forEach
变量声明中使用单数变量名称。例如,将 var="companies"
更改为 var="company"
和 var="countries"
到 var="country"
。)
关于java - JSP页面如何在同一个表中列出两个不同的bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32335218/