Record Bulk Delete

Source: Internet
Author: User

querying and displaying database records for batch selection and deletion

1<% @pageImport= "Com.sp.web.Student"%>2<% @pageImport= "Java.util.List"%>3<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "4pageencoding= "UTF-8"%>5<%@ taglib prefix= "s" uri= "/struts-tags"%>6<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >789<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">Ten<title> Query Display page </title> One A<body> -<s:include value= "toubu.jsp" ></s:include> -<table width= "border=" 1 "cellpadding=" 0 "cellspacing=" 0 "align=" center "bgcolor=" #feeeed "> the<tr align= "right" ><td height= "colspan=" 8 "><s:a action=" Student-back "> Back home </s:a></td ></tr> -<tr style= "font-size:36px" align= "center" ><td height= "" colspan= "8" > Student Information Sheet </td></tr> -&LT;TR align= "center" > -&LT;TD width= ">" <br> Select All <input type= "Radio" name= "Check" onclick= "Checkall (This)" > +Reverse Select <input type= "Radio" name= "Check" onclick= "Checkno (This)" ></td> -&LT;TD width= > Study No. </td> +&LT;TD width= "> Name </td> A&LT;TD width= > Sex </td> at&LT;TD width= "> Date of birth </td> -&LT;TD width= > class </td> -&LT;TD width= "> Modify </td> -<td> Delete </td> -</tr> -<s:iterator value= "#session. List" status= "STA" > in&LT;TR align= "center" > -<td><input type= "checkbox" name= "checkbox" Value= "${sno}" onclick= "SetCheck (This)" ></td> to<td><s:property value= "Sno"/></td> +<td><s:property value= "Sname"/></td> -<td><s:property value= "Ssex"/></td> the<td><s:date name= "Sbirthday" format= "Yyyy-mm-dd"/></td> *<td><s:property value= "Class_"/></td> $<td>Panax Notoginseng<s:a action= "Student-update" onclick= "return confirm (' Confirm that you want to modify it? ') ' > -<s:param name= "Sno" value= "Sno" ></s:param> the</s:a> +</td> A<td><a href= ' student-delete.action?sno=<s:property value= ' sno '/> ' onclick= ' return confirm (' After the deleted data is not recoverable, please choose carefully! \ nyou sure you want to delete it? ') ' > ' delete ' </a></td></tr> the</s:iterator> +<tr align= "Right" > -&LT;TD height= "8" colspan= > Records: ${list.size ()} bar </td></tr> $<s:submit action= "Student-deleteall" type= "button" value= "Delete all" onclick= "Del (This)" ></s:submit> $</table> -</body> - the<script type= "Text/javascript" > -var CKD = document.getelementsbyname ("checkbox");Wuyi function Checkall (ckdall) { the     if(ckdall.checked) { -          for(var i = 0; i < ckd.length; i++) { WuCkd[i].setattribute ("Checked", "checked"); -         } About}Else { $          for(var i = 0; i < ckd.length; i++) { -ckd[i].checked =false; -         } -      A     } +      the      - } $ function Checkno (ckdno) { the      for(var i = 0; i < ckd.length; i++) { the         if(ckd[i].checked) { theckd[i].checked =false; the}Else { -Ckd[i].setattribute ("Checked", "checked"); in         } the          the     } About } the function SetCheck (checkbox) { the     if(checkbox.checked) { theCheckbox.setattribute ("Checked", "checked"); +}Else { -checkbox.checked =false; the     }Bayi      the } the function del (BTN) { -      -var count = 0; thevar value = ""; the      for(var i = 0; i < ckd.length; i++) { the         if(ckd[i].checked) { theCount + = 1; -Value + = Ckd[i].value + ","; the         } the     } the     if(count = = 0) {94Alert ("Please select at least one piece of data!") "); the}Else { theValue = value.substring (0,value.lastindexof (",")); the     if(Confirm ("The deleted data is not recoverable, please choose carefully!") \ nyou sure you want to delete it? ")) {98Window.location.href = "student-deleteall.action?snos=" +value; About     }  -     }101 }102 103</script>

Action method:

1  PublicString DeleteAll () {2String RTN = "";3HttpServletRequest HSQ =servletactioncontext.getrequest ();4String value = Hsq.getparameter ("Snos");5string[] Snos = Value.split (",");6         inti =NewStudentdao (). DeleteAll (Snos);7         if(I >= 0) {8RTN = "Stu-deleteall";9}Else {TenRTN = "Fail"; One         } A         returnRtn; -}

DAO Layer:

1  Public intDeleteAll (string[] snos) {2         intRTN = 0;3 Student Stu;4Configuration cfg =NewConfiguration (). Configure ();5serviceregistry sr =NewStandardserviceregistrybuilder (). Applysettings (Cfg.getproperties ()). build ();6Sessionfactory SF =Cfg.buildsessionfactory (SR);7Session SE =sf.opensession ();8Transaction TR =se.begintransaction ();9     TenString hql = "Delete Student where Sno in" +Snos; One          for(inti = 0; i < snos.length; i++) { AStu = (Student) se.get (Student.class, Snos[i]); - Se.delete (stu); -rtn++; the         } - tr.commit (); - se.close (); - sf.close (); +         returnRtn; -}

Record Bulk Delete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.