我有班级客户
public class Customer {
private long id;
private String firstName;
private String lastName;
private String pesel;
private Address address;
public Customer() {}
public Customer(String firstName, String lastName, String pesel, Address address) {
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.pesel = pesel;
}
}
和班级地址
public class Address {
private String country;
private String city;
private String street;
private String streetNumber;
private String zipCode;
}
我如何输入百里香的形式?我的意思是原始类型,这是应该但我怎么能读地址类?
<form th:action="@{/addCustomer}" method="post" class="col m8 s12 offset-m2">
<div class="row">
<div class="input-field col s6">
<input id="firstName" type="text"/>
<label for="firstName">Imię</label>
</div>
<div class="input-field col s6">
<input id="lastName" type="text"/>
<label for="firstName">Nazwisko</label>
</div>
<div class="row">
<div class="input-field col s6">
<input id="pesel" type="text">
<label for="pesel">Pesel</label>
</div>
</div>
</div>
</form>
当然,类之间的每个关系,基本上类代码都是例如我有哪些字段
答案 0 :(得分:0)
一种方法是将表单元素声明为请求映射方法的输入参数。类似的东西:
@RequestMapping(value = '/trainInfo/trainDetails', method = RequestMethod.POST, produces='text/html')
public ModelAndView getTrainDetails(HttpServletRequest request, HttpServletResponse response,
@RequestParam(name='username') String username) {
其中'username'
是您要在方法内访问的HTML输入元素的名称。