Hibernate简介:
用面向对象的思想去管理数据库,如果程序中都是sql语句,则难以维护。
其他主流的ORM框架技术:Mybatis
hibernate需要配置的jar包:hibernate-core,MySQL-jdbc,junit4
1.建立xml配置文件:hibernate.cfg.xml
<session-factory>
<PRoperty name="connection.username">root</property> <!-- 连接数据库的用户名 --> <property name="connection.passWord">root</property> <!-- 连接数据库的密码 --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- 方言 --> <property name="connection.url">jdbc:mysql:///hibernate?useUnicode=true&characterEncoding=UTF-8</property> <!-- JDBC地址 --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <!-- 数据库JDBC的驱动 --> <property name="myeclipse.connection.profile">MyEclipse Derby</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">create</property> </session-factory>2.创建实体类:
// 1.共有的类// 2.提供共有的不带参数的默认的构造方法// 3.属性私有// 4.属性setget封装
新闻热点
疑难解答