gpt4 book ai didi

java - 动态字段 thymeleaf 列表迭代

转载 作者:行者123 更新时间:2023-11-29 10:00:46 27 4
gpt4 key购买 nike

我遇到了一个非常奇怪的错误!在列表上迭代时,thymeleaf 将索引识别为我的 bean 的属性而不是索引值!

<div th:each="phoneStat : *{phones}">
<select th:field="*{phones[__${phoneStat.index}__].variety}">
<option></option>
</select>
<div class=" input-field col s4">
<input class="validate" th:field="*{phones[__${phoneStat.index}__].number}"
th:id="${'phonenumber-'+ phones[__${phoneStat.index}__]}" type="text"/>
<label th:for="${'phonenumber-'+ phones[__${phoneStat.index}__]}"> Mobile</label>
</div>
</div>

我在这里做错了什么?请帮忙!

2015-06-15 15:48:25.453 ERROR 7764 --- [nio-8080-exec-6] 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: "phoneStat.index" (/custom:89)] with root cause

org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 10): Property or field 'index' cannot be found on object of type 'com.ubleam.corporate.server.model.Phone' - maybe not public?

最佳答案

实际上,当将字段绑定(bind)到表单时,为了访问带有 th:each 作为 doc 的列表指定,我们应该使用两个变量 itemphoneStat:

<div th:each="item, phoneStat : *{phones}">
<select th:field="*{phones[__${phoneStat.index}__].variety}">
<option></option>
</select>
<div class=" input-field col s4">
<input class="validate" th:field="*{phones[__${phoneStat.index}__].number}"
th:id="${'phonenumber-'+ phones[__${phoneStat.index}__]}" type="text"/>
<label th:for="${'phonenumber-'+ phones[__${phoneStat.index}__]}"> Mobile</label>
</div>
</div>

关于java - 动态字段 thymeleaf 列表迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30847056/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com