•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对象赋值了