这篇文章主要讲解:
1>.对Hibernate使用的一些简单封装;
· 2>.在单元测试中,使用Hibernate的封装的工具进行增删改查的测试
1.目录结构展示
2.代码展示
2.0 配置文件 hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- 数据库连接信息 --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <!-- 默认 localhost:3306 --> <property name="connection.url">jdbc:mysql:///test</property> <property name="connection.username">root</property> <property name="connection.password">root</property> <!-- 通用配置 --> <!-- 方言:hibernate要支持多种数据库,根据不同数据库生成对应的sql语句 告诉hibernate使用的什么数据库,以便生成对应数据库的sql --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <!-- 打印sql语句 --> <property name="show_sql">true</property> <!-- 格式化sql --> <property name="format_sql">true</property> <!-- 映射信息 注意映射文件存放的是文档路径 需要用/ --> <mapping resource="cn/vincent/pojo/User.hbm.xml"/> </session-factory> </hibernate-configuration>