所以我在我的html中有这个:
<html xmlns:th="http://www.thymeleaf.org">
<body>
<form th:action="@{/user/set-new-password}" method="post">
<input type="password" name="password" placeholder="Password">
<input type="password" name="matchesPassword" placeholder="Password">
<input type="hidden" th:value="${token}" th:text="${token}">
<input type="submit" class="submit-button" th:value="#{changePassword.submitButton}"/>
</form>
</body>
</html>
控制器:
@GetMapping(value = "/set-new-password")
public String changePasswordForm(Model model, @ModelAttribute("token") String token) {
model.addAttribute("token", token);
return "relatedToUserAccounts/change-password";
}
HTML 看起来像这样
<input type="hidden" value=""></input>
如果令牌="abcd1234",我想看起来像这样
<input type="hidden" value="abcd1234"></input>
对于 th:text,它正在工作,html 显示文本,但 th:value 保持为空。
不要使用th:text
,而是使用name="token"
和th:value="${token}"