我先借鉴一个前辈的帖子:
比如我有一个UserInfo类和一个Address类,前者记录用户的帐号密码,后者记录用户的详细信息。前者也有一个Address属性,这样它们两者是嵌套了。
一种方式是在actionForm中用两个属性UserInfo和Address。
<nested:nest property="userInfo">
<tr align="center">
<td width="88" height="30">用 户 名:</td>
<td width="203"><nested:text property="useraccount" size="30"/></td>
</tr>
<tr align="center">
<td height="30">密 码:</td>
<td><nested:password property="password" size="30"/></td>
</tr>
</nested:nest>
<nested:nest property="address">
<tr align="center">
<td height="30">用户地址:</td>
<td><nested:text property="streetOne" size="30"/></td>
</tr>
</nested:nest>
再有一种方式在actionForm中用一个属性UserInfo,因为Address是UserInfo的一个属性。
<nested:nest property="userInfo">
<tr align="center">
<td width="88" height="30">用 户 名:</td>
<td width="203"><nested:text property="useraccount" size="30"/></td>
</tr>
<tr align="center">
<td height="30">密 码:</td>
<td><nested:password property="password" size="30"/></td>
</tr>
<nested:nest property="address">
<tr align="center">
<td height="30">用户地址:</td>
<td><nested:text property="streetOne" size="30"/></td>
</tr>
</nested:nest>
</nested:nest>
对比下第二种方法更简便
本文通过示例展示了如何在Struts2框架中使用嵌套属性来处理复杂的表单数据,包括用户信息和地址信息的收集。
2229

被折叠的 条评论
为什么被折叠?



