如何告诉 Thymeleaf 填充密码字段?

问题描述 投票:0回答:1
spring-boot thymeleaf
1个回答
0
投票

我目前得到的是以下解决方案:

<form id="registration-form" method="post" th:object="${registrationDto}"
                                           th:action="@{/registration}">

    <input id="name" type="text" name="name" th:field="*{name}"/>

    <input id="password" type="password" name="password" th:value="*{password}"/>

</form>

这似乎有效,我相信,当您省略通过

th:field
显式指定字段时,Thymeleaf 将省略额外的检查。只要
name
属性与表单的 dto 属性正确匹配^^ Thymeleaf 仍然能够正确映射字段。

我不能说这是否是最好的解决方案,但至少它是可行的。

© www.soinside.com 2019 - 2024. All rights reserved.