I. Knowledge of the INFORMATION_SCHEMA database
INFORMATION_SCHEMA database provides a way to access database metadata (data)
The database contains various data such as database name, table name, column name, column data type, etc.
Generating entity classes starts with the database
Ii. displaying all the databases
To generate the entity class, it is very easy to select the database first, this is simply a simple sentence of SQL to get all the database
show databases;
Third, using the tables table to get the table in the database
Next, to display all the tables for the selected database, here is the INFORMATION_SCHEMA database that was mentioned earlier
The tables table below it holds the structure of each table data and table we have created.
Here we only take the name of the table, where DatabaseName is the database name chosen
SELECT from WHERE = ' DBName '
Iv. using the columns table to get the fields and other data in the table
When you select a table, you get the fields in the table, field data types, comments, and so on, regardless of what you choose to generate.
This information can be found in the columns in the INFORMATION_SCHEMA database, as in sql:
SELECT DISTINCT from WHERE = ' TableName ' and = ' DBName '
which
column_name |
Field name |
Data_type |
field data type |
|
Field Comment |
Column_key |
Whether it is a primary key, foreign key, unique index, etc. |
V. Using the resulting data to splice the generated code
Here a little
How the Java generated entity classes are implemented inside the tool (MySQL)