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.persistence.*; import java.sql.Timestamp;

在IDEA中通过Hibernate的反向工程可以快速生成数据库表对应的实体类和映射文件。首先打开项目资源,配置hibernate.cfg.xml连接数据库。接着在Persistence中选择Generate Persistence Mapping,通过Database Schema生成POJO类。简单几步即可完成代码生成。
最低0.47元/天 解锁文章
4612

被折叠的 条评论
为什么被折叠?



