私はツリーをループするネストされた各構造体を持っています。 HTMLコードは次のとおりです。Thymeleafはそれぞれの配列インデックスと配列インデックスをネストしました
<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>
adminユーザーは、各ユーザー配列の0番目のインデックスです。しかし、明らかにそれに到達する表記は失敗します。私はバックエンドのデータが正しいことを確認することができます。このコードがサーバー上で実行される場合 が、私はこのエラーを取得する:
org.springframework.web.util.NestedServletException:リクエスト 処理が失敗しました。ネストされた例外は org.thymeleaf.exceptions.TemplateProcessingExceptionです:例外 評価SpringEL式:「team.users [0] .score」(チーム)
私はこのコードが間違っているかを把握することができず、この問題を解決するネット上の類似の例はありません。ありがとう。
根本原因は何ですか? 「例外を評価するSpringEL式」は、一番外側の例外です。原因を見るために最後のものを見てください。 – Kayaman
はい、3番目の原因が下にあり、 "org.springframework.expression.spel.SpelEvaluationException:EL1025E:(pos 10):コレクションに '0'要素があり、インデックス '0'が無効です" –
まあ、あなたの問題があります。 – Kayaman