zoukankan      html  css  js  c++  java
  • 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对象赋值了
  • 相关阅读:
    Java学习日记Ⅰ
    docker 安装redis
    maven 打包 把第三方包也打进去
    wiki 配置数据源 编码要是utf8 不能是utf8mb4
    SCFT用公钥登录
    配置tomcat重启脚本
    tomcat
    centos7 搭建rabbitmq服务 3.7.15
    安装openoffice
    tomcat 日期切分
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/3992904.html
Copyright © 2011-2022 走看看