我尝试使用 th:each
迭代项目列表,
<div class="row" th:each="item : *{items}">
<input type="text" th:field="item.name"/>
</div>
如果我使用 th:text
访问迭代变量,它会起作用,但会抛出
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'item' available as request attribute
当我使用th:field
访问它时,我哪里做错了?
最佳答案
像这样的东西可能会起作用:
<div class="row" th:each="item, stat : *{items}">
<input type="text" th:field="*{items[__${stat.index}__].name}"/>
</div>
关于java - 无法引用 Thymeleaf 中的迭代变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30125630/