一个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