在页面有id的checkbox,选择后,经过js处理,传给action一个ids(id字符串),action中截取ids,获得id的数组,然后根据id数组做批量操作。
页面:
<input type="checkbox" class="checkbox_list" value="<s:property value="id"/>"/>
js处理checkbox:
function getIds(div){ var item = $("#"+div).find("input[class='checkbox_list']:checked"); if(item.length==0){ alert("请选择!"); return false; }else{ item.each(function(i){ id += this.value + '_'; }); return id; } }
action:
public void deletes(){ try { String ids_ = this.getParameter("ids"); String[] ids = ids_.split("_"); this.iccService.deletes(ids); this.write("ok"); } catch (Exception e) { e.printStackTrace(); } }
ibatis:
<delete id="deletes"> delete tb_table where id in ( <iterate conjunction=",">#[]#</iterate>) </delete>