Spring 将下拉列表值绑定到Thymeleaf中的bean
我有一个下拉框,试图将所选帐号绑定到转账bean中的fromAccount 我在控制器中看到值为nullSpring 将下拉列表值绑定到Thymeleaf中的bean,spring,spring-boot,thymeleaf,Spring,Spring Boot,Thymeleaf,我有一个下拉框,试图将所选帐号绑定到转账bean中的fromAccount 我在控制器中看到值为null <select class="form-control" th:field="${customer.transferBean.fromAccount}"> <option th:each="fromAccount: ${customer.accountBean}"
<select class="form-control" th:field="${customer.transferBean.fromAccount}">
<option
th:each="fromAccount: ${customer.accountBean}"
th:value="${fromAccount.accountNum}"
th:text="${fromAccount.accountNum}" ></option>
</select>
不知道我错过了什么。我正在使用spring boot和thymeleaf来编写html
谢谢。您使用了错误的语法
"th:field="${customer.transferBean.fromAccount}"
对于指定绑定字段,您应该使用*{}
而不是${}
,并且只能在父级或子级上与th:object
组合使用
有关bindingm的更多详细信息,请参阅Thymeleaf文档谢谢。你是对的,我使用了错误的语法。
"th:field="${customer.transferBean.fromAccount}"