来自:https://blog.csdn.net/chenyunqiang/article/details/81026823php
一、构建项目并添加项目结构配置以及配置初始参数
1.一、如图将基本的架子搭建好java
1.二、点击File,弹出的菜单中点击Project Structure;
1.三、点击左侧的Modules,再点击“+”号,再在弹出的菜单中选择Hibernate;
1.四、在这时,项目中多出了一个Hibernate,点击Hibernate,再点击“+”号,选择hibernate.hbm.xml;
1.五、弹出的窗口中选择Hibernate的版本,而后点击OK;
1.六、点击OK后在原来1.4步骤的窗口中的Apply按妞应用到项目;
1.七、这时项目架子中多出了一个名为hibernate.hbm.xml的配置文件;
1.八、在hibernate.hbm.xml中配置以下配置;
-
<?xml version=‘1.0’ encoding=‘utf-8’?>
-
<!DOCTYPE hibernate-configuration PUBLIC
-
“-//Hibernate/Hibernate Configuration DTD//EN”
-
“http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd”>
-
<hibernate-configuration>
-
-
-
<property name=“connection.url”>jdbc:mysql://localhost:3306/SSHBlog?useUnicode=true&characterEncoding=utf8&useSSL=true&zeroDateTimeBehavior=convertToNull</property>
-
-
<property name=“connection.driver_class”>com.mysql.jdbc.Driver</property>
-
-
<property name=“connection.username”>root</property>
-
-
<property name=“connection.password”></property>
-
-
-
-
-
</hibernate-configuration>
1.九、第一步配置完毕。
二、配置数据库
2.一、点击左下角按钮,使窗口样式如图所示;
2.二、选择数据库;
2.四、配置数据库后测试链接是否成功,若成功后点击肯定;
2.五、数据库以下;
三、生成Hibernate的实体类以及配置文件
3.一、点击窗口中的Persistence;
3.二、在Persistence中右键项目,而后点击Generate Persistence Mapping,选择By Database Schema;
3.三、选择数据源,配置实体类包,选择要生成的实体类(其中日期类型的只能手动修改成java.util.Date),而后点击OK;
3.四、等待一段时间以后,发现项目中的实体类以及配置文件已经自动生成。