Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 将下拉列表值绑定到Thymeleaf中的bean_Spring_Spring Boot_Thymeleaf - Fatal编程技术网

Spring 将下拉列表值绑定到Thymeleaf中的bean

Spring 将下拉列表值绑定到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}"

我有一个下拉框,试图将所选帐号绑定到转账bean中的fromAccount

我在控制器中看到值为null

            <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}"