Hibernate3.3 note, hibernate3.3 note
// ---------------- Transaction (modify, delete, and save) Session s = getSession (); Transaction t = s. beginTransaction (); getSession (). delete (persistentInstance); t. commit (); // query statement public List <Cls> I = new ArrayList <Cls> (); public String execute () {ClsDAO clsDAO = new ClsDAO (); I = clsDAO. findAll (); return "1";} // Delete statement
StuDAO In = new StuDAO (); I = In. findstuid (stu_id); In. delete (I. get (0); // Add the statement public String stu_name; public Integer stu_age; public Integer cls_id; public String execute () {ClsDAO clsDAO = new ClsDAO (); cls cls = clsDAO. findById (cls_id); StuDAO stuDAO = new StuDAO (); Stu stu = new Stu (cls, stu_name, stu_age); stuDAO. save (stu); return "1" ;}// modify the statement public String stu_name; public Integer stu_age; public Integer cls_id; public Integer stu_id; public String execute () {ClsDAO clsDAO = new ClsDAO (); Cls cls = clsDAO. findById (cls_id); Stu stu = new Stu (cls, stu_name, stu_age, stu_id); // you can write your own constructor StuDAO studentsDAO = new StuDAO () with the primary key ID (); studentsDAO. merge (stu); return "1" ;}// the student table in DAO queries the public List findClsid (Integer cls_id) according to the class ID) {String queryString = "from Stu where cls_id = '" + cls_id + "'"; Query queryObject = getSession (). createQuery (queryString); return queryObject. list ();} // JS-based pseudo-webpage direct access to action, used without triggering, <script type = "text/javascript"> window. location. href = "all. action "; </script>
// S tag, traverse the List array, and generate tables and other data tables <% @ taglib prefix = "s" uri = "/struts-tags" %> <s: iterator value = "I"> <s: property value = "stuId"/> </s: iterator>
//struts2 <constant name="struts.i18n.encoding" value="utf-8" /><package name="denglu" extends=" struts-default"><action name="all" class="com.all"><result name="1">/all.jsp</result></action> <action name="up_save" class="com.up_save"><result name="1" type="redirectAction">all</result></action></package>
Tag a returns to the previous step.
<A href = "javascript: history. go (-1)"> return </a>
JS form cannot be empty for Detection
<Script type = "text/javascript"> function myCheck () {for (var I = 0; I <document. form1.elements. length-1; I ++) {if (document. form1.elements [I]. value = "") {document. getElementById ("showResult "). innerHTML = "Enter the complete student information! "; Document. form1.elements [I]. focus (); return false ;}} return true ;}</script> <form name = "form1" action = "add. action "method =" post "onSubmit =" return myCheck () "> </form> <span id =" showResult "style =" color: red; "> </span>