程序猿全敏
2015-11-22 16:31:19
原
三大框架之hibernate入门学习教程增删改查
好久没更新分享了!现在发下三大框架的hibernate便于初学者学习!另外struts2的那些配置文件代码可以找我要,里面包括如何自定义拦截器等等。开始hibernate的学习吧!首先不多说先导包!
新建hibernate.cfg.xml文件
<hibernate-configuration> <session-factory> <property name="connection.url"> jdbc:mysql://localhost/student?useUnicode=true&characterEncoding=UTF-8 </property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="connection.username"> root </property> <property name="connection.password"> root </property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> </session-factory> </hibernate-configuration>
主要是连接数据库
新建学生实体Student。
新建orm映射文件Student.hbm.xml
<hibernate-mapping> <class name="com.qm.entity.Student" table="students"> <id name="id" column="studentId" type="java.lang.Integer"> <generator class="identity"></generator> </id> <property name="name" column="studentName" type="string"></property> <property name="password" column="studentPassword" type="string"></property> <property name="hight" column="studentHight" type="int"></property> <property name="sex" column="studentSex" type="int"></property> </class> </hibernate-mapping>
这个Student类和数据库表一一对应,我将id作为自增属性的
再在hibernate.cfg.xml加入来挂载orm映射
<mapping resource="com/qm/entity/Student.hbm.xml"/>
现在就可以来写持久层来进行增删改查了!
Configuration conf=new Configuration(); conf.configure("hibernate.cfg.xml"); //创建工厂 SessionFactory sf=conf.buildSessionFactory(); //取得session Session session=sf.openSession(); //开始事务 session.beginTransaction(); Student student=new Student("quanmina","123",172,1); session.save(student); System.out.println("保存成功"); session.getTransaction().commit(); session.close(); sf.close();
这是增加一个学生的代码!其他的见文件包!
总体结构截图
增加运行截图
查询一个截图!
查询所有截图!
这是我的数据表设计
猜你喜欢
- hibernate简单demo实例源代码下载
- spring+hibernate+bootstrap整合实现分页的功能
- java servlet+hibernate通过Ajax实现的简单成绩查询项目实例
- Struts2+Hibernate基本配置及基本功能代码(附整理学习笔记)
- Hibernate基础教程的Demo代码下载
- Spring MVC+Hibernate整合开发实现联系人的增删改查入门实例
- struts+Hibernate+MySQL的新闻发布管理系统后台+前台
- JSP hibernate开发实现青匆校园留言本源代码下载
- hibernate 入门增删改查demo
- 精通hibernate源码
- Spring 4 MVC + Hibernate 4 + Maven开发用户增删改查入门实例
- 使用hibernate作为底层,jquery实现级联操作(附带oracle数据库)
请下载代码后再发表评论
文件名:hibernate.rar,文件大小:7043.569K
下载
- /
- /hibernate
- /hibernate/hibernate_1
- /hibernate/hibernate_1/.classpath
- /hibernate/hibernate_1/.mymetadata
- /hibernate/hibernate_1/.project
- /hibernate/hibernate_1/.settings
- /hibernate/hibernate_1/.settings/.jsdtscope
- /hibernate/hibernate_1/.settings/org.eclipse.wst.jsdt.ui.superType.container
- /hibernate/hibernate_1/.settings/org.eclipse.wst.jsdt.ui.superType.name
- /hibernate/hibernate_1/src
- /hibernate/hibernate_1/src/com
- /hibernate/hibernate_1/src/com/qm
- /hibernate/hibernate_1/src/com/qm/dao
- /hibernate/hibernate_1/src/com/qm/entity
- /hibernate/hibernate_1/src/com/qm/entity/Student.hbm.xml
/hibernate/hibernate_1/src/com/qm/entity/Student.java
- /hibernate/hibernate_1/src/com/qm
- /hibernate/hibernate_1/src/hibernate.cfg.xml
- /hibernate/hibernate_1/src/com
- /hibernate/hibernate_1
- /hibernate

- hibernate简单demo实例源代码下载
- hibernate 入门增删改查demo
- 精通hibernate源码
- 使用hibernate作为底层,jquery实现级联操作(附带oracle数据库)
- 原 spring+hibernate+bootstrap整合实现分页的功能
- 深入浅出hibernate书籍的源代码下载
- 原证 Hibernate基础教程的Demo代码下载
- 用Hibernate实现领域对象的自定义字段
- hibernate操作oracle数据库JPA的@Column注释灵活修改class变量名称
- hibernate操作Oracle数据库插入数据
- 原证 Struts2+hibernate4+layui+mysql简单的网站后台管理系统
- 原 java servlet+hibernate通过Ajax实现的简单成绩查询项目实例

周敏国 LV9
2022年10月22日
丶右转 LV11
2020年11月18日
名字随便的啦啦 LV7
2020年10月23日
林志勇 LV10
2020年4月28日
a837535114 LV10
2020年2月5日
段朝洪 LV15
2019年11月25日
我的名字是凑得 LV8
2018年12月23日
973445486 LV6
2018年12月12日
nanjing2017 LV15
2018年11月20日
hhit_zh LV6
2018年10月11日

卢本伟不开挂 LV4
2024年4月27日
liang85 LV1
2023年6月30日
女王不该在山炮村养花 LV8
2023年4月16日
彩色天空 LV5
2023年4月2日
周敏国 LV9
2022年10月22日
微信网友_6186189978783744
2022年10月22日
暂无贡献等级
cqbscxh LV11
2022年9月19日
wubinbin LV11
2021年12月18日
c123456x LV2
2021年12月9日
Ye55555
2021年12月6日
暂无贡献等级