我在我们的应用程序中有类似如下的需求,
我想以表格的形式显示以下详细信息。
Country Name Population CapitalCity Aria
US XX XX XX XX
IN YY YY YY YY
用户可以在配置页面中选择他有兴趣查看的列。
在后端,我设置了如下模型属性(使用spring MVC),
model.addAttribute("selColumns", "column keys");
model.addAttribute("countryDetails", "List of country details");
在CountryDetail类中,字段名称和selColumns键名是相同的。
class CountryDetails {
private String country,
population,
CapitalCity,
Aria;
}
在UI中,我尝试使用以下代码来实现相同的功能。
<table class="table table-hover table-bordered table-striped">
<thead>
<tr>
<c:forEach items="${selColumns}" var="item">
<th><spring:message code="${item}" /></th>
</c:forEach>
</tr>
</thead>
<tbody>
<c:forEach items="${countryDetails}" var="det">
<tr>
<c:forEach items="${selColumns}" var="item">
<td>
//Below code is not working
<c:out value="${item.det}" /></td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
表头工作正常。但是我很难只显示已配置列的行信息。代码无法工作,因为它试图在Java端找到getDet()。
有人能帮我吗?在JSP中有没有什么方法,如果我给属性(字段)名,相应的值就会返回?
像这样的东西
提前谢谢你,凯蒂
发布于 2018-05-28 19:42:27
试试这个吧。
<tbody>
<c:forEach items="${countryDetails}" var="det">
<tr>
<c:forEach items="${selColumns}" var="item">
<td>
<c:out value="${det[item]}" />
</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
注意:
selColumns = ["Country", "Population", "CapitalCity", "Aria"]
CountryDetails properties = Country,Population,CapitalCity,Aria
https://stackoverflow.com/questions/50565388
复制相似问题