Struts2的表单标签还可以为集合中的对象赋值

•Struts 还允许填充 Collection 里的对象, 这常见于需要快速录入批量数据的场合
 

代码如下 :

TestCollectionAction.java

 1 package com.atguigu.struts2.app;
 2 
 3 
 4 import java.util.Collection;
 5 
 6 import com.atguigu.struts2.model.Manager;
 7 import com.opensymphony.xwork2.ActionSupport;
 8 
 9 public class TestCollectionAction extends ActionSupport {
10 
11     /**
12      * 
13      */
14     private static final long serialVersionUID = 1L;
15 
16     private Collection<Manager> mgrs = null;
17     
18     public Collection<Manager> getMgrs() {
19         return mgrs;
20     }
21 
22     public void setMgrs(Collection<Manager> mgrs) {
23         this.mgrs = mgrs;
24     }
25 
26     public String execute() throws Exception {
27         System.out.println(mgrs);
28         return SUCCESS;
29     }
30 }

manager-input.jsp

 1     
 2                 <form action="testConversion2.action">
 3     
 4         <table>
 5         
 6             <tbody>
 7                 
 8                 <tr>
 9                     <td>Mgrs[0].Name:</td>
10                     <td><input name="mgrs[0].name"/></td>
11                 </tr>
12                 
13                 <tr>
14                     <td>Mgrs[0].Birth:</td>
15                     <td><input name="mgrs[0].birth"/></td>
16                 </tr>
17                 
18                 <tr>
19                     <td colspan="2" align="right">
20                         <input type="submit" value="Submit"/>
21                     </td>
22                 </tr>
23             
24             </tbody>
25             
26         </table>
27         
28     </form>
mgrs[0].birth这样表示就可以为集合中的mgrs对象赋值了

转载于:https://my.oschina.net/JeremySoftware/blog/687071

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值