//----------------事务(修改、删除、保存)
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%);
}

  

Hibernate3.3 小记的更多相关文章

  1. [原]Paste.deploy 与 WSGI, keystone 小记

    Paste.deploy 与 WSGI, keystone 小记 名词解释: Paste.deploy 是一个WSGI工具包,用于更方便的管理WSGI应用, 可以通过配置文件,将WSGI应用加载起来. ...

  2. MySql 小记

    MySql  简单 小记 以备查看 1.sql概述 1.什么是sql? 2.sql发展过程? 3.sql标准与方言的关系? 4.常用数据库? 5.MySql数据库安装? 2.关键概念 表结构----- ...

  3. Git小记

    Git简~介 Git是一个分布式版本控制系统,其他的版本控制系统我只用过SVN,但用的时间不长.大家都知道,分布式的好处多多,而且分布式已经包含了集中式的几乎所有功能.Linus创造Git的传奇经历就 ...

  4. 广州PostgreSQL用户会技术交流会小记 2015-9-19

    广州PostgreSQL用户会技术交流会小记 2015-9-19 今天去了广州PostgreSQL用户会组织的技术交流会 分别有两个session 第一个讲师介绍了他公司使用PostgreSQL-X2 ...

  5. 东哥读书小记 之 《MacTalk人生元编程》

         一直以来的自我感觉:自己是个记性偏弱的人.反正从小读书就喜欢做笔记(可自己的字写得巨丑无比,尼玛不科学呀),抄书这事儿真的就常发生俺的身上. 因为那时经常要背诵课文之类,反正为了怕自己忘记, ...

  6. Paypal支付小记

    Paypal支付小记 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !impo ...

  7. SSH整合(struts2.3.24+hibernate3.6.10+spring4.3.2+mysql5.5+myeclipse8.5+tomcat6+jdk1.6)

    终于开始了ssh的整合,虽然现在比较推崇的是,ssm(springmvc+spring+mybatis)这种框架搭配确实比ssh有吸引力,因为一方面springmvc本身就是遵循spring标准,所以 ...

  8. linux 下cmake 编译 ,调用,调试 poco 1.6.0 小记

    上篇文章 小记了: 关于 Poco::TCPServer框架 (windows 下使用的是 select模型) 学习笔记. http://www.cnblogs.com/bleachli/p/4352 ...

  9. mongodb入门学习小记

    Mongodb 简单入门(个人学习小记) 1.安装并注册成服务:(示例) E:\DevTools\mongodb3.2.6\bin>mongod.exe --bind_ip 127.0.0.1 ...

随机推荐

  1. Struts的类型转换

    struts中jsp提交的数据,struts会自动转换为action中的属性类型: 对于基本的数据类型以及日期类型会自动转换: 就像前面那一篇博客的代码封装一样,会把字符串类型传过来的数据转化为相应的 ...

  2. cocos2d-x 判断系统语言

    转自:http://blog.csdn.net/tangaowen/article/details/8878193 //default language is local language ccLan ...

  3. C#实现在Winform中嵌入Word和Excel

    http://www.cnblogs.com/wuzi145/archive/2012/05/08/2490680.html 在此只是介绍一个简单控件:dsoframer.ocx的使用,这个控件需要通 ...

  4. 7za 解压文件

    7za.exe x -aoa 完美国际补丁.7z 7za.exe x -aoa 完美国际补丁.7z -o"C:\Users\Admin\AppData\Local\Temp\完美国际补丁&q ...

  5. 一个仿 github for windows 及 windows 8 的进度条

    https://github.com/wly2014/ProgressBar

  6. 基于Android 平台简易即时通讯的研究与设计[转]

    摘要:论文简单介绍Android 平台的特性,主要阐述了基于Android 平台简易即时通讯(IM)的作用和功能以及实现方法.(复杂的通讯如引入视频音频等可以考虑AnyChat SDK~)关键词:An ...

  7. css中那些你可能没注意到的东西

    1.inline元素,添加position:absolute;可定宽高,position:relative;则不行,不信你试试! 2.inline元素添加浮动后,不用加display:block;也可 ...

  8. [008]new、delete及动态内存分配

    1.new和delete都会用,这里只声明一点: C++ 没有明确定义如何释放指向不是用 new 分配的内存地址的指针. 比如下面的代码: #include<iostream> using ...

  9. 文件和目录之umask函数

    本篇博文内容摘自<UNIX环境高级编程>(第二版),仅作个人学习记录所用.关于本书可参考:http://www.apuebook.com/. umask函数为进程设置文件模式创建屏蔽字,并 ...

  10. iOS开发中图片方向的获取与更改

    iOS开发中 再用到照片的时候  或多或少遇到过这样的问题  就是我想用的照片有横着拍的有竖着排的  所以导致我选取图片后的效果也横七竖八的   显示效果不好 比如: 图中红圈选中的图片选取的是横着拍 ...