jsp页面添加一个集合数组到action(用序列化提交)
2015-12-21 11:56
801 查看
页面的js
页面jsp
action中接收直接用集合接收就好(遍历成对象来添加到数据库)
//点击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); }
相关文章推荐
- Ext.js5表单—请联系我们(41)
- JavaScript Array: slice vs splice
- 对javascript匿名函数的理解(透彻版)
- 新手理解HTML、CSS、javascript之间的关系
- 几个简单的js正则验证
- javascript中隐藏显示的样式表属性
- 自定义标签(JspFragment类、invoke方法、开发带属性的标签)
- Ext.js5表单—登录表单(40)
- Ext.js5小鲱鱼域(表单域)(39)
- Js 获取当前时间
- Flow之一个新的Javascript静态类型检查器
- 获取手机验证码js计时器
- Ext.js5(radio group布局能力)(38)
- ArcGIS JavaScript API 4.0 beta 1
- JavaScript跨域总结与解决办法 什么是跨域
- json操作工具-LitJson
- Ext.js5(验证)(CheckboxGroup 类的布局能力)(37)
- 细说 Jsp
- JS each 跳出
- javascript 初学对象