This is the 7th day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021
An open source system has recently been used in the production environment: Zoe has an interesting and productive section called “code generators.”
Its function in the module menu: System tools -> code generation. Let’s look at his code generation logic.
Tool Usage
-
Build table
To use code generation, we first need to create a business table in the database, for example, we want to create the user table of the system: table name is my_user, as shown below
-
The import
Go to System Tools > Code Generation and click Import.
In the popup window, check my_user and click “OK”, then you can see the imported table in the list interface:
-
Code review
Click “Preview” after my_user to see the pre-generated code, which is generated quickly with little delay.
Java, mapper. Java, service. Java, ServicePl. Java, Controller.java, Mapper.xml and front-end.vue files and interface request.js files.
Code generation logic research
SQL to find
Let’s examine the code generation logic in terms of the interfaces requested by each step.
When you click “import”, the window pops up a list of tables in the database. We debug the F12 browser and find that its call interface is /tool/gen/db/list. In the background, we check this interface. The interface entry is in the ruoyi-Generator section as shown in the following figure.
Its SQL query is searched step by step in gentableMapper.xml:
Let’s copy it:
SELECT
table_name,
table_comment,
create_time,
update_time
FROM
information_schema. TABLES
WHERE
table_schema = (SELECT DATABASE())
AND table_name NOT LIKE 'qrtz_%'
AND table_name NOT LIKE 'gen_%'
AND table_name NOT IN (
SELECT
table_name
FROM
gen_table
)
ORDER BY
create_time DESC
Copy the code
SELECT DATABASE() queries the name of the current DATABASE. Information_schema. TABLES displays all databases currently connected to this mysql server. The field table_COMMENT will display the comments we wrote when we created the table, which is this part of navcat: