IDEA 下 hibernate 反向生成实体和映射文件
选中项目,鼠标右键项目,选择Add Frameworks Support 或者 选中项目+F4或者 选中项目+F4
现在看resources多了hibernate.cfg.xml
接下来配置hibernate.cfg.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>
<session-factory>
<!--数据库连接url配置-->
<property name="connection.url">jdbc:mysql://localhost:3306/disaster_tolerant</property>
<!--数据库驱动配置-->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<!--数据库用户名配置-->
<property name="connection.username">root</property>
<!--数据库密码配置-->
<property name="connection.password">123456</property>
</session-factory>
</hibernate-configuration>
连接你的数据库
在Persistence中右键项目,然后点击Generate Persistence Mapping,选择By Database Schema
勾勾选选的,你懂的
最后生成的pojo文件给 大家 OB一哈
package com.nelsoner.pojo.test; import javax.persistenc