我有类User和userRole,我需要在User中绑定UserRole对象 我试过下面的代码
UserRole.java
public class UserRoleBean {
private Integer role_id;
private String roleName;
private String roleDesc;
//getter setter
}
User.java
public class UserBean {
private Integer userId;
private String firstName;
private String lastName;
private Date dob;
private String emailAddr;
private String mobileNo;
private Integer balance;
private String password;
private UserRoleBean roleBean;
//getter and setter;
}
AddUser.jsp
<form:form method="POST" action="saveUser.html" modelAttribute="userBean">
<table>
<tr>
<td><form:label path="userId">User ID:</form:label></td>
<td><form:input path="userId" value="${user.userId}" readonly="true"/></td>
</tr>
<tr>
<td><form:label path="firstName">First Name:</form:label></td>
<td><form:input path="firstName" value="${user.firstName}"/></td>
</tr>
<tr>
<td><form:label path="lastName">Last Name :</form:label></td>
<td><form:input path="lastName" value="${user.lastName}"/></td>
</tr>
<tr>
<td><form:label path="emailAddr">Email Address :</form:label></td>
<td><form:input path="emailAddr" value="${user.emailAddr}" readonly="false"/></td>
</tr>
<tr>
<td><form:label path="dob">Date Of Birth:</form:label></td>
<td><form:input path="dob" /></td>
</tr>
<tr>
<td><form:label path="mobileNo">Mobile No :</form:label></td>
<td><form:input path="mobileNo" value="${user.mobileNo}"/></td>
</tr>
<tr>
<td><form:label path="password">Password:</form:label></td>
<td><form:password path="password" value="${user.password}"/></td>
</tr>
<tr>
<td><form:label path="balance">Balance:</form:label></td>
<td><form:input path="balance" value="${user.balance}"/></td>
</tr>
<tr>
<td><form:label path="roleBean">Select Role:</form:label></td>
<td>
<form:select path="roleBean">
<form:option value="0" label="Select" />
<form:options items="${forRoles}" itemValue="role_id" itemLabel="roleName" />
</form:select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="${cap}"/></td>
</tr>
</table>
</form:form>
其他属性是绑定但是roleBean无法绑定,如何执行此操作,
任何帮助将不胜感激
答案 0 :(得分:1)
您必须像设置User对象一样单独设置roleBean
的每个属性。
设置roleBean
的任何属性时,roleBean.role_id
使用Id
,'roleName'使用`roleBean.roleName'。
您的roleName
路径就像<form:select path="roleBean">
一样,但如果<form:select path="roleBean.roleName">
为roleName
,则应为func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let settingsHeaderSectionCell:SettingsHeaderSectionCell = self.dequeueReusableCell(withIdentifier: "SettingsHeaderSectionCell") as! SettingsHeaderSectionCell
return settingsHeaderSectionCell
}
。其他属性也是如此。