0
林傳遞模型屬性從控制器到thymeleaf形式,所以我可以結合對象是這樣的:Thymeleaf構造對象
<div class="container" style="max-width: 600px" th:fragment="signupForm">
<form name="f" th:action="@{/signup}" th:object="${userCredentials}" method="post" class="form-horizontal">
<input th:placeholder="#{messages.form.email}" type="text" th:field="*{email}"
name="email" id="email" class="form-control"/>
<input th:placeholder="#{messages.form.name}" type="text" th:field="*{name}"
name="name" id="name" class="form-control"/>
<input type="password" th:placeholder="#{messages.form.password}" th:field="*{password}"
id="password" name="password"/>
<button type="submit" th:text="#{messages.form.signup}"></button>
</form>
</div>
但是我想重新使用此形式從其它視圖片段,但我不能t因爲${userCredentials}
表單對象沒有被初始化。我可以以這種方式構建這個對象嗎?
<div th:if="${userCredentials == null}" th:with="userCredentials=new UserCredentials()"></div>