【发布时间】:2017-01-03 22:12:11
【问题描述】:
在我的 Spring/Thymeleaf/Hibernate 项目中,我需要能够将元素添加到我的编辑对象的字段(即 List)。我是怎么做到的,因为不允许嵌入? 类似的东西:
@Entity
public class Recipe {
@Id
private int id;
private String name;
private String description;
private List<String> steps;
}
还有我的百里香模板:
<form th:action="@{|/save/${recipe.id}|}" method="post" th:object="${recipe}">
<input type="hidden" th:field="${recipe.id}" th:value="${recipe.id}"/>
<input type="text" th:field="${recipe.name}" th:value="${recipe.name}"/>
<input type="text" th:field="${recipe.description}" th:value="${recipe.description}"/>
<input th:each="step : ${recipe.steps}" type="text" th:field="${step}" th:value="${step}"/>
<!-- And here I want make ability add new step element to List<String> steps -->
如何制作,而不丢失已编辑的Recipe对象数据?
使用<form> 和<button type="submit"> 添加?
还是只使用<a href>?那么如何不丢失输入的数据呢?
【问题讨论】:
标签: java html spring thymeleaf