Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Thymeleaf嵌套了each和数组索引_Java_Html_Spring_Thymeleaf - Fatal编程技术网

Java Thymeleaf嵌套了each和数组索引

Java Thymeleaf嵌套了each和数组索引,java,html,spring,thymeleaf,Java,Html,Spring,Thymeleaf,我有一个嵌套的结构,每个结构在树中循环。Html代码如下所示: <div th:each="group : ${groups}" class="row corp-teams-group-row"> <h2 th:text="'- ' + ${group.name}">GROUP NAME</h2> <div th:each="team : ${group.teams}" class="row corp-teams-teams-row"&g

我有一个嵌套的结构,每个结构在树中循环。Html代码如下所示:

<div th:each="group : ${groups}" class="row corp-teams-group-row">
    <h2 th:text="'- ' + ${group.name}">GROUP NAME</h2>
    <div th:each="team : ${group.teams}" class="row corp-teams-teams-row">
        <h2 th:text="'- ' + ${team.name}">TEAM NAME</h2>
        <div class="col-xs-6 corp-man-wrapper corp-admin-wrapper">
            <div class="corp-user-image-container">
                <div class="corp-user-image-wrapper">
                    <img th:src="${team.users[0].image}">
                </div>
                <div class="corp-bugcount"><span th:text="${team.users[0].score}"></span></div>
            </div>
            <div class="corp-user-data-container">
                <h2 th:text="${team.users[0].name} + ' ' + ${team.users[0].surname}"></h2>
                <div class="corp-user-email" th:text="${team.users[0].email}"></div>
            </div>
        </div>
        <div class="col-xs-6 corp-man-wrapper">
            <h3 th:text="${team.newFeatureCount}"></h3>
            <h3 th:text="${team.defectCount}"></h3>
        </div>
        <div th:each="user : ${team.users}" class="col-xs-6 corp-man-wrapper">
            <div class="corp-user-image-container">
                <div class="corp-user-image-wrapper">
                    <img th:src="${user.image}">
                </div>
                <div class="corp-bugcount"><span th:text="${user.score}"></span></div>
            </div>
            <div class="corp-user-data-container">
                <h2 th:text="${user.name} + ' ' + ${user.surname}"></h2>
                <div class="corp-user-email" th:text="${user.email}"></div>
            </div>
        </div>
    </div>
</div>

组名
队名
管理员用户是每个用户数组的第0个索引。但是达到它的符号显然是失败的。我可以确认后端数据是正确的。 当此代码在服务器上运行时,我遇到此错误:

org.springframework.web.util.NestedServletException:请求 处理失败;嵌套异常是 org.thymeleaf.exceptions.TemplateProcessingException:异常 评估SpringEL表达式:“team.users[0].score”(teams)


我无法找出这段代码的错误,网络上也没有类似的例子可以解决这个问题。谢谢。

如评论中所述:异常的原因是

"org.springframework.expression.spel.SpelEvaluationException‌​: EL1025E:(pos 10): The collection has '0' elements, index '0' is invalid"

如果
team.users
可以有零个元素,只需添加一个th:if条件

根本原因是什么?“异常计算SpringEL表达式”只是最外层的异常。查看最后一个以查看原因。是的,它在底部有第三个原因,上面写着“org.springframework.expression.spel.SpelEvaluationException:EL1025E:(位置10):集合有“0”元素,索引“0”无效“好吧,这是您的问题。这是您的答案;-)然后添加一个th:如果可能发生这种情况,您可以将其作为解决方案编写,我将接受作为答案。谢谢。请发布一个代码片段好吗?