我有一个名字输入字段:
<input th:field="*{fleet.firstName}" class="signup1" type="text" id="fname" name="fname" autofocus="" required=""/>
我有两个表/对象“舰队”和“服务”。如果百里香仅允许我在每个输入字段中使用一个对象,该怎么办?
我尝试了两次输入th:field,但是没有用。喜欢:
<input th:field="*{fleet.firstName}" th:field="*{service.firstName}" class="signup1" type="text" id="fname" name="fname" autofocus="" required=""/>
我认为这是不可能的。您可以使用要在Web端查看的字段的并集为Thymeleaf创建DTO对象。然后,将其分为服务层中的数据库表。
就像是:
选项1:无对象
<form th:action="@{/destination}">
<input type="text" th:value="${service.firstName}" name="service.firstName"/>
<input type="text" th:value="${fleet.firstName}" name="fleet.firstName"/>
<button type="submit">Go</button>
</form>
选项2:
网路
<form th:action="@{/destination}" th:object="${myThymeleafFormObject}">
public class ThymeleafForm {
private String fleetFirstName;
private String serviceFirstName;
...
}
服务
public class MyService {
// To avoid complexity maps the ThymeleafForm in different JPA entities
// Logic and repository calls
}
储存库
public class FleetServiceRepositoryJPA {
//Database operations for fleet table
}
public class ServiceRepositoryJPA {
//Database operations for service table
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句