Spring boot 百里香表
当我想为每个I.index获取错误java.lang.NumberFormatException:设置值时,我遇到了问题表:“${I.index}”。在数组中我需要numer,所以${i.index}是int。我不知道我做错了什么Spring boot 百里香表,spring-boot,thymeleaf,Spring Boot,Thymeleaf,当我想为每个I.index获取错误java.lang.NumberFormatException:设置值时,我遇到了问题表:“${I.index}”。在数组中我需要numer,所以${i.index}是int。我不知道我做错了什么 <div class="form-group row" th:each="attribute, i: ${attributeList}"> <label class="col-sm-3
<div class="form-group row" th:each="attribute, i: ${attributeList}">
<label class="col-sm-3 col-form-label" th:text="${attribute.name}"></label>
<div class="col-sm-9">
<input type="text" th:field="*{technicalAttributes[${i.index}].name}" class="form-
control" placeholder="Nazwa">
</div>
</div>
您不能像不使用预处理那样嵌套表达式(
*{…${…}}
)。您的代码应该如下所示:
<div class="form-group row" th:each="attribute, i: ${attributeList}">
<label class="col-sm-3 col-form-label" th:text="${attribute.name}"></label>
<div class="col-sm-9">
<input type="text" th:field="*{technicalAttributes[__${i.index}__].name}" class="form-control" placeholder="Nazwa">
</div>
</div>
(如果您没有使用th:field属性,表达式
*{technicalAttributes[i.index].name}
也将是合适的。但是由于您使用th:field,您必须使用预处理。)您不能像不使用预处理那样嵌套表达式(*{…${…}}
)。您的代码应该如下所示:
<div class="form-group row" th:each="attribute, i: ${attributeList}">
<label class="col-sm-3 col-form-label" th:text="${attribute.name}"></label>
<div class="col-sm-9">
<input type="text" th:field="*{technicalAttributes[__${i.index}__].name}" class="form-control" placeholder="Nazwa">
</div>
</div>
(如果未使用th:field属性,则表达式*{technicalAttributes[i.index].name}
也适用。但由于使用th:field,因此必须使用预处理。)