Connect to the database and generate entity classes in IDEA

1. Connect to the database


(1) As shown below, click view-----select tool windows-----select database and click




(2) Pop up the Database window, click the plus sign ------------ select data source --------------- Select the database you want to add and click





(3) Pop up the DataSources and Drivers window, fill in the circled boxes respectively.

 host-----write ip address

Database-------write database name

user-------write account

Password------ write password


After filling in, you can click test Connection. If the connection is successful, a sentence will be displayed on the right side of the test Connection button to indicate that the connection is successful. After the connection is successful, click OK in the lower right corner.




(4) After clicking OK, the following result appears, and a database appears under Database.




2. Generating entities

(1) As shown in the figure, click view---------select tool windows---------------------select persistence and click




(2) After clicking persistence, the persistence window will appear, and the database we connected to appears under persistence, which is pointed by the arrow.




(3) As shown in the figure below, select and click the added database ------------------- Select Generate Persistence Mapping --------- Select By Database Schema and click





(4) Click By Database Schema, a window will pop up, fill in the circled part


choose Data Source ------------------------Click the lower right triangle to select the database

Package----------------------Select a package in the project, the generated entity will become a class file and placed under that package

The third part shows the tables of the database, each table generates an entity, check it, and then press OK in the lower right corner. This will generate the entity.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324885459&siteId=291194637