zoukankan      html  css  js  c++  java
  • jsp页面添加一个集合数组到action(用序列化提交)

    页面的js

    //点击a标签增加删除
            var i=0;
            $("#a").on("click",function(){
                var $newtr = $("<tr  id='model'>"  
                            +"<td><input type='text' name='contactsList["+i+"].contactName' value=''></td>"  
                            +"<td><input type='text' name='contactsList["+i+"].contactTel' value=''></td>"  
                            +"<td><input type='text' name='contactsList["+i+"].contactFax' value=''></td>"  
                            +"<td><input type='text' name='contactsList["+i+"].contactEmail' value=''></td>" 
                            +"<td><input type='text' name='contactsList["+i+"].contactRole' value=''></td>"
                            +"<td ><a href='javascript:void(0);' class='del'>删除</a></td>"
                            +"</tr>");
                  i++;
                $newtr.find(".del").click(function(){
                    $(this).parents("tr").remove();
                });
                $("#fourdiv").append($newtr);            
            });

    页面jsp

    <div id="a" style="color:blue;cursor:pointer"><h4>添加一个联系人</h4></div>
                <div id="thirddiv">
                    <table id="fourdiv">
                        <tr>
                            <th>姓名</th>
                            <th>电话</th>
                            <th>传真</th>
                            <th>邮箱</th>
                            <th>职务</th>
                            <th>操作</th>
                        </tr>
                    </table>
                </div>

    action中接收直接用集合接收就好(遍历成对象来添加到数据库)

    private List<Contacts> contactsList = new ArrayList<Contacts>();//页面接收联系人的数组
        public List<Contacts> getContactsList() {
            return contactsList;
        }
    
        public void setContactsList(List<Contacts> contactsList) {
            this.contactsList = contactsList;
        }
        //添加多条联系人
            for(Contacts contacts:contactsList){
                contacts.setCustomId(customs.getId());
                this.customsService.addContacts(contacts);
            }
  • 相关阅读:
    解决HbuilderX乱码问题
    IDEA
    关于Git开发的一些注意事项
    postgresql
    启动新拉取项目流程
    关于能发布但无法打包的问题
    关于人脸感知设备(类似门禁考勤设备)搜索添加显示成功但却添加不上的问题
    在GitLab上创建项目并上传初始文件
    中控标替换成白标开发
    工厂模式
  • 原文地址:https://www.cnblogs.com/xuerong/p/5062970.html
Copyright © 2011-2022 走看看