小华132 2021-03-02 11:13 采纳率: 0%
浏览 132

th:each的作用域问题

一个table表格,在第一个td里面通过下标访问有语法提示且运行正常,在第二个td里面访问虽然有语法提示但是运行报错,报错
运行正常代码:
<table width="100%">

    <tr th:each="goods1,goodsIndex:${goods}" th:if="${goodsIndex.index}%2==0">

        <td width="50%">

            <table width="100%"><tr><td><img th:src="${goods[goodsIndex.index].getImg_src()}" /> <img th:src="${goods[goodsIndex.index].getImg_src()}" /></td></td></tr></table>

        </td>

        <td width="50%">

            <table width="100%"><tr><td></td></td></tr></table>

        </td>
        
    </tr>

</table>

运行错误代码:

<table width="100%">
    <tr th:each="goods1,goodsIndex:${goods}" th:if="${goodsIndex.index}%2==0">

        <td width="50%">

            <table width="100%"><tr><td><img th:src="${goods[goodsIndex.index].getImg_src()}" /></td></td></tr></table>

        </td>

        <td width="50%">

            <table width="100%"><tr><td> <img th:src="${goods[goodsIndex.index].getImg_src()}" /></td></td></tr></table>

        </td>

    </tr>

</table>

报错信息:

org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "goods[goodsIndex.index].getImg_src()" (template: "section" - line 27, col 47)

2021-03-02 11:10:59.980 ERROR 1332 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "goods[goodsIndex.index].getImg_src()" (template: "section" - line 27, col 47)] with root cause

  • 写回答

3条回答 默认 最新

  • CSDN问答专家001 2021-03-02 12:06
    关注

    th:each放在需要便利的容器的父容器中,然后子容器用其中的数据遍历。

    实际用法可参考:https://www.cnblogs.com/SeaWxx/p/10276171.html

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮