The JSP page
The < table > < tr > < th > < input id = "all" type = "checkbox" / > < / th > < th > standard no. < / th > < th > Chinese name < / th > < th > version < / th > < th > release date < / th > The < th > implementation date < / th > < th > action < / th > < / tr > < c: forEach items = "${stdList}" var = "STD" > < tr > < td > < input name = "id" type = "checkbox" value="${std.id }" /></td> <td>${std.std_num }</td> <td>${std.zhname }</td> <td>${std.version }</td> <td><fmt:formatDate value="${std.release_date }" pattern="YYYY-MM-dd"/></td> <td><fmt:formatDate value="${std.impl_date }" The pattern = "YYYY - MM - dd" / > < / td > < td > < a href = "${STD. Package_path}" target = "_blank" > download < / a > & have spent <a href="edit.html? Id = ${STD. Id} "> change < / a > < / td > < / tr > < / c: forEach > < / table > < button id =" del "> batch delete < / button > < script type =" text/javascript" SRC ="statics/js/jquery-1.12.4.js"></script> <script type="text/javascript" oall=document.getElementById("all"); var oid=document.getElementsByName("id"); oall.onclick=function(){ for(var i=0; i<oid.length; I ++){// All select boxes and all select the same oid[I]. Checked =oall.checked; }}; // Click the check box for(var I =0; i<oid.length; I ++){oid[I]. Onclick =function(){var j=0; j<oid.length; j++){ if(oid[j].checked==false){ oall.checked=false; break; }else{ oall.checked=true; }}}; $("#del"). Click (function(){var ids=""; var n=0; for(var i=0; i<oid.length; I++) {if (oid [I] checked = = true) {/ / selected to true var id = oid [I] value; if(n==0){ ids+="ids="+id; }else{ ids+="&ids="+id; } n++; Ids =1&ids=2&ids=3&ids=4...... $.get (" del. HTML ", ids, function (data) {if (data = = "\" ok \ "") {alert (" deleted successfully!" ); Href =" findallstandardlist.html "; }else{alert(" Delete failed!" ); }}); }); </script>Copy the code
The controller controller
@requestMapping (value="/del.html") @responseBody public String delStansard(Integer[] ids){// RequestMapping(value="/del.html") @responseBody public String delStansard(Integer[] ids) {/ / batch delete standardBiz delStandardInfo (ids); } catch (Exception e) {// TODO: handle Exception return "error"; } return "ok"; }Copy the code
MyBatis batch delete SQL statement
<delete id="delUserById"> DELETE FROM `USER` WHERE id in <foreach collection="array" item="ids" open="(" separator="," close=")"> <! Separator is a comma. Close is a close parenthesis. --> #{ids} </foreach> </delete>Copy the code