我有一个包含Address对象的Person对象:
class Person {
private int age;
private Address address;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address= address;
}
}
一个班级地址:
class Address{
private String streetAddress;
private String city;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getStreetAddress() {
return state;
}
public void setStreetAddress(String streetAddress) {
this.state = state;
}
}
在我的Spring网络流程中,我有:
<var name="person" class="Person"/>
<var name="address" class="Address"/>
<view-state id="view1" view="qualificationView" model="person">
<transition on="submitApplication" to="view2"/>
</view-state>
我的HTML有属性:
age
streetAddress
city
在表单提交上,我看到“age”属性被正确绑定,但是没有设置Address类中的属性。
如何设置所有字段?
答案 0 :(得分:1)
<form:input type="text" path="address.streetAddress"/>
您不需要定义<var name="address".../>
。我认为您必须在address
至Person
中明确初始化new Address()
。