青春、染指流年 2022-01-18 19:10 采纳率: 57.1%
浏览 172
已结题

<c:forEach>标签如何遍历List<实体>中的实体(Object对象)

######controller层相关代码:

List<PsAcctDeps> psAcctDeps = this.psAcctDepsService.getByParam(paramMap);//[com.bank.perf.perfps.entity.PsAcctDeps@247039, com.bank.perf.perfps.entity.PsAcctDeps@5843ae41]
model.put("psAcctDeps",psAcctDeps);
jsp页面的forEach
<table><tr>
                <td class="showContentAttrName">客户号:</td>
                <td>

                  <%-- 方法1:这个报Property "0" not found on type ...错误  --%>
                <c:forEach var="obj" items="${psAcctDeps}" varStatus="status"> 
                 ${obj[status.index].custNo} 
                </c:forEach>
                </td>
                
                <%-- <td>${psAcctDeps.custNo}</td>    方法2:这个报For input string: "custNo"错误  --%>

            </tr></table>


运行结果及报错内容
我的解答思路和尝试过的方法
想知道foreach标签这边怎么接收list集合里Object对象的值?万分感谢!
  • 写回答

1条回答 默认 最新

  • 像风一样  2022-01-18 19:48
    关注
    <%-- 方法1:这个报Property "0" not found on type ...错误  --%>
    <%-- 方法1报这个错误是因为obj是psAcctDeps中的元素, obj[status.index]obj不是数组或list,就会报错--%>
    <c:forEach var="obj" items="${psAcctDeps}" varStatus="status"> 
        <tr>
            <td align="center">${obj.属性名}</td>
        </tr>
    <%-- <td>${psAcctDeps.custNo}</td>    方法2:这个报For input string: "custNo"错误  --%>
    <%-- 方法2报这个错误是因为psAcctDeps是list,${psAcctDeps[0].custNo}才行--%>
    </c:forEach>
    

    望采纳,谢谢

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 2月18日
  • 已采纳回答 2月10日
  • 创建了问题 1月18日