//----------------事务(修改、删除、保存)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 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>
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) / intPageSize
action之间传值
<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%); }
新闻热点
疑难解答