//----------------事務(修改、刪除、保存)session s=getSession();Transaction t=s.beginTransaction();getSession().delete(persistentInstance);t.commit();//查詢語句public List<Cls> i = new ArrayList<Cls>();public String execute(){ClsDAO clsDAO = new ClsDAO();i=clsDAO.findAll();return "1";}//刪除語句StuDAO In=new StuDAO();i=In.findstuid(stu_id);In.delete(i.get(0));//添加語句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";}//修改語句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);//自己寫個參數包含主鍵ID的構造函數StuDAO studentsDAO=new StuDAO();studentsDAO.merge(stu);return "1";}//DAO里面學生表按照班級ID查詢public List findClsid(Integer cls_id) {String queryString = "from Stu where cls_id = '"+cls_id+"'";Query queryObject = getSession().createQuery(queryString);return queryObject.list();}//JS 方式 偽網頁直接訪問action,用于無觸發情況下,需要調用后臺訪問數據庫取得實時數據的做法<script type="text/javascript">window.location.href="all.action";</script>//S標簽,遍歷List數組,生成表格等數據表<%@ taglib
//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>
a標簽返回上一步<a href="Javascript:history.go(-1)">返回</a>JS表單不能為空檢測
<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="請輸入學生完整信息!"; 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>
分頁 在任何系統中都是非常頭疼的事情,有的數據庫在語法上支持分頁,而有的數據庫則需要使用可滾動游標來實現,并且在不支持可滾動游標的系統上只能使用單向游標逐步接近要取得的數據。 Hibernate提供了一個支持跨系統的分頁機制,這樣無論底層是什么樣的數據庫都能用統一的接口進行分頁操作。比如下面的代碼就是從第500條開始取出100條記錄:
Query q = session.createQuery("from FooBar as f"); q.setFirstResult(500); q.setMaxResults(100); List l = q.list();分頁計算總頁數
int intPageSize; //一頁顯示的記錄數int intRowCount; //記錄總數int intPageCount; //總頁數計算總頁數公式:intPageCount = (intRowCount+intPageSize-1) / intPageSizeaction之間傳值
<action name ="app09002Action" class ="app09002Action" > <result name="success" type="redirect-action"> <param name="actionName">app10001Action</param>action地址 <param name="userId">${userId}</param>值<param name="userId">${userId}</param>值</result> </action>CSS樣式,文字下面的一根分隔線,很好看,支持IE
#wrapper h1:after{ content: ' ';display: block;width: 100%;height: 2px;margin-top: 10px;background: -moz-linear-gradient(left, rgba(147,184,189,0) 0%, rgba(147,184,189,0.8) 20%, rgba(147,184,189,1) 53%, rgba(147,184,189,0.8) 79%, rgba(147,184,189,0) 100%); background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(147,184,189,0)), color-stop(20%,rgba(147,184,189,0.8)), color-stop(53%,rgba(147,184,189,1)), color-stop(79%,rgba(147,184,189,0.8)), color-stop(100%,rgba(147,184,189,0))); background: -webkit-linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%); background: -o-linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%); background: -ms-linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%); background: linear-gradient(left, rgba(147,184,189,0) 0%,rgba(147,184,189,0.8) 20%,rgba(147,184,189,1) 53%,rgba(147,184,189,0.8) 79%,rgba(147,184,189,0) 100%); }
|
新聞熱點
疑難解答