我有2个对象员工和员工地址。
这是我的2个对象 -
员工
@Entity
@Table(name="Employee")
//@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private Timestamp created;
@Temporal(TemporalType.DATE)
private Date dob;
private String email;
@Column(name="FATHER_NAME")
private String fatherName;
private String firstname;
private String lastname;
private String married;
@Column(name="MOTHER_NAME")
private String motherName;
private String telephone;
//bi-directional many-to-one association to EmployeeAddress
@OneToMany(mappedBy="employee")
private List<EmployeeAddress> employeeAddresses;
public Employee() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public Timestamp getCreated() {
return this.created;
}
public void setCreated(Timestamp created) {
this.created = created;
}
public Date getDob() {
return this.dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFatherName() {
return this.fatherName;
}
public void setFatherName(String fatherName) {
this.fatherName = fatherName;
}
public String getFirstname() {
return this.firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return this.lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getMarried() {
return this.married;
}
public void setMarried(String married) {
this.married = married;
}
public String getMotherName() {
return this.motherName;
}
public void setMotherName(String motherName) {
this.motherName = motherName;
}
public String getTelephone() {
return this.telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public List<EmployeeAddress> getEmployeeAddresses() {
return this.employeeAddresses;
}
public void setEmployeeAddresses(List<EmployeeAddress> employeeAddresses) {
this.employeeAddresses = employeeAddresses;
}
public EmployeeAddress addEmployeeAddress(EmployeeAddress employeeAddress) {
getEmployeeAddresses().add(employeeAddress);
employeeAddress.setEmployee(this);
return employeeAddress;
}
public EmployeeAddress removeEmployeeAddress(EmployeeAddress employeeAddress) {
getEmployeeAddresses().remove(employeeAddress);
employeeAddress.setEmployee(null);
return employeeAddress;
}
EmployeeAddress
@Entity
@Table(name="employee_address")
@NamedQuery(name="EmployeeAddress.findAll", query="SELECT e FROM EmployeeAddress e")
public class EmployeeAddress implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String apt_no;
private String city;
private String country;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="create_dt")
private Date createDt;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="end_dt")
private Date endDt;
private String state;
private String street_addr;
private String zip_Code;
//bi-directional many-to-one association to Employee
@ManyToOne
@JoinColumn(name="emp_id")
private Employee employee;
public EmployeeAddress() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getApt_no() {
return this.apt_no;
}
public void setApt_no(String apt_no) {
this.apt_no = apt_no;
}
public String getCity() {
return this.city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return this.country;
}
public void setCountry(String country) {
this.country = country;
}
public Date getCreateDt() {
return this.createDt;
}
public void setCreateDt(Date createDt) {
this.createDt = createDt;
}
public Date getEndDt() {
return this.endDt;
}
public void setEndDt(Date endDt) {
this.endDt = endDt;
}
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
public String getStreet_addr() {
return this.street_addr;
}
public void setStreet_addr(String street_addr) {
this.street_addr = street_addr;
}
public String getZip_Code() {
return this.zip_Code;
}
public void setZip_Code(String zip_Code) {
this.zip_Code = zip_Code;
}
public Employee getEmployee() {
return this.employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
现在,我如何将此作为对象传递给我的JSP来收集员工信息。
如何显示地址属性..
例如: - 我显示如下的名字,它工作正常,但我如何显示address.street,address.zip等?
<form:form method="post" action="addemployee" commandName="employee">
<table class="TFtable">
<tr>
<td><form:label path="firstname"><spring:message code="label.firstname"/></form:label></td>
<td><form:input path="firstname" /></td>
</tr>