我有 3 个实体用户、部门和地址。用户可以有多个地址。现在我对构建这个用例的表单有疑问。
我可以直接访问部门,因为它是对象。但我不知道如何引用地址属性,因为它是一个集合。
class Users
{
private int id;
private String name;
private Department dept;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "userId", nullable = false)
private Set<Address> addresses = new HashSet<Address>(0);
//Getters and setters
}
MyForm.jsp
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<title>Spring 3 MVC Series - Contact Manager</title>
</head>
<body>
<h2>Contact Manager</h2>
<form:form method="post" commandName="userObject" action="addPerson.html">
<table>
<tr>
<td><form:label path="name">Name</form:label></td>
<td><form:input path="name" /></td>
</tr>
<tr>
<td><form:label path="userObject.dept.deptName">Department Name</form:label></td>
<td><form:input path="userObject.dept.deptName" /></td>
</tr>
<tr>
<td><form:label path="userObject.addresses.street">Street Address</form:label></td>
<td><form:input path="userObject.addresses.street" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Add Contact"/>
</td>
</tr>
</table>
</form:form>
如何使用对象访问我的 jsp 表单中的地址属性。我在 userObject.addresses.street 的 jsp 中遇到问题