IDEA连接数据库自动生成实体类
Posted wulihong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA连接数据库自动生成实体类相关的知识,希望对你有一定的参考价值。
1.连接数据库
(1)按下图 , 点击view-----选择tool windows----------选择database并点击

(2)弹出Database窗口,点击加号------------选择data source---------------选择想添加的数据库并点击

(3)弹出DataSources and Drivers窗口,分别填写画圈的方框。
host-----写ip地址
Database-------写数据库名称
user-------写账号
Password------写密码
填好之后,可以点击一下test Connection,如果连接成功,那么test Connection按钮的右边会显示 一句话提示连接成功。连接成功后就点击右下角的OK。

(4)点击OK后出现如下结果,Database下出现一个数据库。

二.添加JPA
1. 先点击file,找见Project Structure

2.点击Modules 再点击+号。我这里是使用的JPA

三.生成实体
(1)按下图, 点击view---------选择tool windows---------------------选择persistence并点击

(2)点击persistence后会出现persistence窗口,persistence下出现我们连接的数据库,就是箭头指向的。

(3)按下图, 选中并单击添加的数据库------------------选择Generate Persistence Mapping---------选择By Database Schema并点击

(4)点击By Database Schema ,弹出如窗口,填写圈起来的部分
choose Data Source ------------------------点击右边下三角选择数据库
Package----------------------选择项目中的某个包,生成的实体将会变成一个类文件放在那个包下
第三部分显示的是数据库的表,每个表生成一个实体,勾选,想要生成实体的表,然后按右下角OK即可。这样就可以生成实体了。

以上是关于IDEA连接数据库自动生成实体类的主要内容,如果未能解决你的问题,请参考以下文章