Database table structure reverse engineering code generation method and system

By receiving user configuration parameters, parsing database table structure metadata, and calling a template engine to generate code, this method solves the diverse adaptation problem in existing Java backend development technologies, achieves efficient and customized end-to-end code generation, improves development efficiency and code consistency, and reduces maintenance and technical barriers.

CN121635957APending Publication Date: 2026-03-10SHENZHEN XUNFANG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511819968.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-04
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

Existing technologies cannot meet the diverse and low-cost adaptation needs of different projects, cannot achieve highly customized templates and full-link code generation, and have high adaptation thresholds, making it difficult to adapt to diverse Java backend development needs.

Method used

This paper provides a method and system for generating reverse engineering code from database table structures. By receiving user configuration parameters, selecting a template, parsing database table structure metadata, mapping database field types to object-oriented programming language types, calling a template engine to render and generate code, and supporting syntax validation and dependency handling.

Benefits of technology

It improves development efficiency by more than 180 times, reduces debugging time by 80%, ensures consistent code style, reduces maintenance costs by 50%, lowers the technical threshold by 70%, supports incremental generation, avoids code overwriting, and meets the needs of more than 95% of Java backend projects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121635957A_ABST
    Figure CN121635957A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of database reverse engineering, in particular to a database table structure reverse engineering code generation method and system, and aims to solve the problems of repeated labor, different styles, poor adaptability, high technical stack coupling and the like of manual writing from a MySQL table to Java full-layer codes. According to the method, database receiving, table selection, output and technical stack adaptation configuration are carried out; providing a preset template library and a user-defined template; the MySQL metadata are analyzed, and field type mapping is achieved; the metadata and the template placeholders are bound, and Entity, Mapper, Service and Controller full-layer codes are generated through rendering; and outputting through local output, preview or Git integration. According to the method, full-process automation is realized, the template customization threshold is low, multiple technical stacks are adapted, and the development efficiency and code consistency are greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database reverse engineering technology, and in particular to a method and system for generating reverse engineering code for database table structures. Background Technology

[0002] In the field of Java backend development, reverse engineering of "database table → Java code" is a core step in the development of business systems based on MySQL databases. However, manually writing entity classes, data access layers, business logic layers, control layers, and CRUD basic interfaces has many pain points: high cost of repetitive labor and easy to make mistakes; chaotic code style due to differences in developers' habits, making maintenance difficult; existing tools are difficult to adapt to and integrate Lombok, and are not compatible with customized needs such as different technology stacks; and the cost of refactoring is extremely high when switching technology stacks.

[0003] Commonly used database reverse engineering tools still have significant limitations: mainstream tools such as MyBatis Generator can only generate entity classes and Mapper-related files, with fixed templates and no support for multi-module configuration; MyBatis-PlusGenerator, although supporting Service layer generation, relies on hard coding for template customization, is strongly coupled with specific technology stacks, and does not support embedding business logic; JPA reverse engineering only focuses on entity class generation, has insufficient mapping of MySQL-specific fields, and lacks customization capabilities; self-developed scripts have poor reusability and lack syntax validation and incremental generation mechanisms.

[0004] These existing technologies fail to address the core needs of "highly customizable templates, end-to-end code generation, and low-barrier adaptation." They either have fixed templates, high customization barriers, or only cover a portion of the code layer, and are often coupled with specific technology stacks, making them difficult to adapt to diverse needs. Therefore, there is an urgent need for a reverse engineering technology that supports highly customizable templates, automated end-to-end code generation, and low-barrier adaptation. Summary of the Invention

[0005] In view of this, the purpose of this invention is to propose a method and system for generating reverse engineering code for database table structures, so as to solve the problem that the existing technology cannot meet the diverse and low-cost adaptation needs of different projects.

[0006] To achieve the above objectives, this invention provides a method for generating reverse engineering code for database table structures, comprising the following steps: Step S1: Receive user configuration parameters, which include database configuration, table selection configuration, output configuration, and technology stack adaptation configuration. Step S2: Use a template selected from the preset template library, or use a user-defined template; Step S3: Parse the metadata of the relational database table structure and implement the mapping between database field types and object-oriented programming language types to obtain standardized metadata of the table structure; Step S4: Bind the standardized metadata of the parsed table structure to the variable placeholders of the template selected in step S2, and call the template engine to render and generate code; Step S5: Output the generated code in the specified manner.

[0007] Preferably, in step S1, the database configuration includes the database connection address, port, username, password, and database name; the table selection configuration includes specifying the target table for production code; the output configuration includes the code generation path and code coverage strategy; and the technology stack adaptation configuration includes specifying the target technology stack, whether to integrate annotations required by the specified framework, whether to integrate annotations required for data validation, and whether to generate annotations required for interface documentation.

[0008] Preferably, the relational database is a MySQL database, and the object-oriented programming language is Java.

[0009] Preferably, in step S2, the custom template pattern is compatible with multiple template engines, including Freemarker and Thymeleaf, and defines template variables with unified semantics and names. The template variables correspond to the core information of the table structure, including table name variables, field name variables, Java field type variables, and field comment variables.

[0010] Preferably, the parsing of metadata of the relational database table structure in step S3 includes: The target table's metadata is obtained by querying the MySQL system tables. The metadata includes table name, table comment, field name, field type, field length, whether it is a primary key, whether it is NOT null, default value, and field comment. The mapping between database field types and object-oriented programming language types allows users to customize mapping rules; the parsing layer can also identify the primary key, index information, and foreign key relationships of the table, and the primary key includes single primary keys and composite primary keys.

[0011] Preferably, step S3 further includes identifying the primary key, index information, and foreign key relationships of the table, and automatically adding ORM mapping annotations when generating code based on the identification results.

[0012] Preferably, in step S4, the step of calling the template engine to render and generate code includes: The system invokes a preset template engine and renders complete code text that perfectly matches the style and structure of the selected or user-defined template at the corresponding level.

[0013] Preferably, after step S4, the method further includes: performing syntax verification and dependency processing on the generated code; The syntax verification includes an integrated Java syntax verifier to check the generated code for syntax and, if errors are found, prompt the user to correct the template in real time. The dependency processing includes automatically identifying the dependencies required to generate the code, generating the corresponding dependency configuration fragments, and prompting the user to add them.

[0014] Preferably, in step S5, the code output methods include local file output, previewing the generated code in a visual interface, and version control integration. When the project is connected to Git, the version control integration automatically ignores existing code files and only commits newly added code files.

[0015] This invention also provides a database table structure reverse engineering code generation system, comprising: The requirement input layer is used to receive user configuration parameters, which include database configuration, table selection configuration, output configuration, and technology stack adaptation configuration. The template customization layer allows users to use templates selected from a pre-set template library or user-defined templates. The parsing layer parses the metadata of the relational database table structure and implements the mapping between database field types and object-oriented programming language types to obtain standardized metadata of the table structure. The code generation layer binds the standardized metadata of the parsed table structure with the variable placeholders of the template selected in step S2, and calls the template engine to render and generate code. The output layer outputs the generated code in a specified manner.

[0016] The beneficial effects of this invention are: 1. This invention can improve development efficiency, reducing the time for generating full-layer code for a single table from 30 minutes manually to within 10 seconds, and batch generation of multiple tables (such as 10 tables) takes only 1 minute, improving development efficiency by more than 180 times; at the same time, it avoids syntax errors caused by manual writing and reduces debugging time by 80%.

[0017] 2. This invention features highly customizable templates to adapt to all scenarios, supporting a dual mode of "basic templates + custom templates". It satisfies the "out-of-the-box" needs of beginners and also allows experienced developers to customize templates to adapt to special scenarios (such as encrypted field annotations in financial projects and embedded permission verification logic in government projects), covering more than 95% of Java backend project needs.

[0018] 3. This invention can ensure consistent code style and reduce maintenance costs. By generating code through a unified template, it ensures that all developers have completely consistent code styles (naming conventions, annotation usage, method structure). During later maintenance, there is no need to adapt to different coding habits, and maintenance efficiency is improved by more than 50%. At the same time, it supports template version management, and the template can be updated for project iterations (such as when upgrading from Java 8 to Java 17, only the syntax in the template needs to be updated, without redeveloping).

[0019] 4. This invention can be adapted with low barriers to entry, reducing technical dependence. The visual template editor requires no development skills, and product / test personnel can also participate in template customization. Technology stack adaptation configuration (such as MyBatis / MP / JPA switching) only requires checking the options, without modifying the code, which lowers the technical threshold for project teams and reduces the onboarding time for new members by 70%.

[0020] 5. This invention can avoid code overwriting through incremental generation and security protection. The incremental generation mode only generates code for newly added tables and does not overwrite existing code (especially Service / Controller with added business logic), solving the pain point of existing tools that "generate and overwrite all code with one click". At the same time, it supports code preview and syntax verification to ensure that the generated code can be directly compiled and run, reducing the cost of "manual correction after generation". Attached Figure Description

[0021] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only for this invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 This is a schematic diagram of the database table structure reverse engineering code generation method according to an embodiment of the present invention; Figure 2 This is a block diagram of a database table structure reverse engineering code generation system according to an embodiment of the present invention. Detailed Implementation

[0023] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments.

[0024] It should be noted that, unless otherwise defined, the technical or scientific terms used in this invention should have the ordinary meaning understood by one of ordinary skill in the art to which this invention pertains. The terms "first," "second," and similar terms used in this invention do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0025] Example 1: like Figure 1 As shown in the embodiments of this specification, a method for generating reverse engineering code from a database table structure is provided, particularly for generating Java language code from a reverse engineering MySQL database table structure. The method includes the following steps: Step S1: Receive all configuration parameters input by the user through the visual configuration interface or configuration file. The user configuration parameters cover the core constraint information of the entire code generation process, specifically including database configuration, table selection configuration, output configuration, and technology stack adaptation configuration. To ensure the stable execution of subsequent processes, the parameters will be automatically validated after being received, such as verifying the availability of the database connection, checking the permissions of the output path, and verifying the rationality of the technology stack combination. If there is an invalid configuration, error information will be fed back in real time and guidance will be provided for correction.

[0026] The database configuration includes core MySQL database connection information, such as the MySQL connection address, port, username, password, and target database name. After configuration, the system will establish a stable connection with the database via JDBC. The table selection configuration specifies the target tables for code generation, supporting precise selection of a single table and batch selection of multiple tables. It also supports wildcard filtering mode; for example, entering "sys_*" will select all tables prefixed with "sys_", suitable for batch generation scenarios. The output configuration includes the code generation path and code coverage strategy. The generation path supports fine-grained configuration for multi-module projects, such as specifying the Entity layer code to the "src / main / java / com / xxx / entity" directory and the Mapper layer to the "src / main / java / com / xxx / mapper" directory. The coverage strategy provides two modes: incremental generation and full generation. The incremental mode will first scan the existing code files in the target path and only generate code for newly added tables or tables with structural changes, completely avoiding overwriting existing manually written business code.

[0027] The technology stack adaptation configuration is used to match the technology selection requirements of different projects. This includes specifying the target technology stack (such as pure MyBatis, MyBatis-Plus enhanced framework, JPA persistence framework, etc.), choosing whether to integrate Lombok annotations to simplify entity class code, whether to integrate Validation annotations to implement data validation, and whether to generate Swagger interface documentation annotations to support visual management of interfaces. All configuration items provide a combination of preset options and custom input, taking into account both convenience and flexibility.

[0028] Step S2: Based on the technology stack adaptation configuration in Step S1, select the corresponding code generation template. The template selection method includes directly selecting from the preset template library or customizing the template based on the user's personalized needs. The two methods can be seamlessly switched to cover different scenarios.

[0029] As an efficient implementation method, the pre-built template library contains 5 mainstream templates that have been proven in practice, including "Pure MyBatis Template", "MyBatis-Plus+Lombok Template", "MyBatis-Plus+Lombok+Swagger Template", "JPA Basic Template", and "JPA+Swagger Template", covering more than 80% of common development scenarios. Users do not need to write templates; they can simply select one based on their technology stack configuration. The template library supports backend updates and upgrades, and can synchronously add templates combining mainstream technologies.

[0030] For personalized needs, a custom template mode is provided, compatible with both Freemarker and Thymeleaf, two mainstream template engines. Users can choose the corresponding engine based on their familiarity to create personalized templates. To lower the customization threshold, the system defines a unified "template variable placeholder" specification. Core placeholders include {{tableName}} (table name), {{tableComment}} (table comment), {{fieldName}} (field name), {{fieldComment}} (field comment), {{javaType}} (Java field type), and {{primaryKey}} (primary key identifier). Users do not need to concern themselves with the underlying metadata parsing logic; they only need to arrange the code structure using placeholders. For example, in the Service layer template, the {{fieldName}} placeholder will automatically populate the table field names. A visual template editor is also provided, supporting features such as template syntax highlighting, automatic placeholder suggestions, and real-time preview of the generated effect. Non-developers can also customize templates by dragging and dropping components and filling in blanks, such as quickly adjusting the naming format of Service layer methods or uniformly adding permission verification annotations or exception handling logic in the Controller layer.

[0031] Step S3: Establish a database connection based on the database configuration in Step S1, perform a comprehensive parsing of the metadata of the target MySQL database table structure, and complete the mapping between database field types and Java types according to preset rules. Finally, output standardized table structure metadata to provide structured data support for subsequent code generation.

[0032] In one implementation, step S3 specifically includes the following sub-steps: 1. Metadata Query: By executing a query statement against the MySQL system table information_schema.columns, the full metadata information of the target table is obtained. The query content covers key information such as table name, table comments, field names, field primitive types, field length, precision, whether it is a primary key, whether it has a NOT NULL constraint, default value, field comments, etc., ensuring that no table structure details are missed. 2. Type mapping rules: The system has a built-in optimized MySQL field type and Java type mapping table, such as mapping int type to Integer, varchar type to String, datetime type to LocalDateTime, decimal type to BigDecimal, etc. At the same time, it supports user-defined mapping rules. For example, users can change the tinyint(1) type from the default Byte mapping to Boolean to adapt to the development habits of Boolean value scenarios. 3. Structure Parsing and Standardization: The retrieved metadata is parsed in a structured manner, identifying the table's primary key information (supporting both single and composite primary keys; composite primary keys will indicate the order of each primary key field), index information (recording index name, related fields, and index type), and foreign key relationships (clearly defining the target table and related fields). The parsing results are integrated with the type mapping results to generate standardized metadata for the table structure, including a list of fields, Java types of each field, primary key information, table comments, and relationships. This metadata will be stored in JSON format for easy interaction with the template engine later.

[0033] In particular, during the structure parsing process, the system will preset corresponding ORM mapping annotation rules based on the identified table structure features. For example, after identifying the primary key field, it will automatically match the @Id or @TableId annotation, and after identifying the foreign key association, it will match annotations such as @OneToMany, @ManyToOne, and @JoinColumn, laying the foundation for the automatic generation of annotations in the subsequent Entity layer code.

[0034] Step S4: Perform precise data binding between the standardized metadata of the table structure output in Step S3 and the template selected in Step S2, call the corresponding template engine to execute the template rendering process, and automatically generate full-layer Java code that conforms to the template style and table structure characteristics, so as to achieve seamless conversion from metadata to directly usable code.

[0035] As a highly efficient and automated implementation method, step S4 specifically includes the following sub-steps: 1. Data Binding: The system first cleans and formats the standardized metadata of the table structure. For example, it converts the underscore naming of table names to camelCase naming of Java class names (e.g., sys_user to SysUser) and the underscore naming of field names to camelCase naming of Java attributes (e.g., create_time to createTime), and filters out invalid data. Then, according to the variable placeholders preset in the template, the formatted metadata is bound to the corresponding placeholders one by one, forming a mapping relationship table of "placeholder-actual data". This ensures that each placeholder can accurately match the corresponding data, providing accurate data input for template rendering. 2. Template Rendering and Automated Code Generation: The template engine loads the selected templates at each level (including Entity layer templates, Mapper layer templates, Service interface templates, Service implementation class templates, and Controller layer templates; in MyBatis scenarios, it also includes Mapper XML templates) in step S2, and automatically executes the process of "hierarchical traversal - template loading - data injection - code generation". Entity layer: Automatically generate class definitions (the class name corresponds to the camel case naming of the table name) and property definitions for each field (the property name corresponds to the camel case naming of the field, and the property type is the mapped Java type) based on the field information in the standardized metadata. Automatically add ORM mapping annotations (such as @TableName to specify the table name, @TableId to mark the primary key, @TableField to specify the field mapping relationship), Lombok annotations (such as @Data to simplify getter / setter methods), Validation annotations (such as @NotBlank for non-null validation), and Swagger annotations (such as @ApiModelProperty to add field descriptions). At the same time, generate the default constructor method and toString method of the class; Mapper layer: Generate the Mapper interface and the corresponding XML file (in the MyBatis scenario). The interface automatically inherits the base interface of the corresponding technology stack (such as inheriting BaseMapper<Entity class> in the MyBatis-Plus scenario), and generate the declarations of the basic CRUD methods according to the table structure; The corresponding select, insert, update, and delete statements are automatically generated in the XML file. The table names and field names in the statements are replaced with actual values through placeholders, and at the same time, it supports optimizing the query statement according to the index information; Service layer: Generate the Service interface and implementation class. The interface automatically inherits the base interface of the technology stack (such as inheriting IService<Entity class> in the MyBatis-Plus scenario), and declare the basic CRUD business methods; The implementation class inherits ServiceImpl<Mapper interface, Entity class>, and automatically injects the Mapper interface instance to implement the default implementation of the basic business methods, and at the same time reserves an extension interface for custom business logic; Controller layer: Generate a RESTful Controller class, add the @RestController annotation and @RequestMapping annotation (the request path is automatically generated according to the table name, such as the sys_user table corresponds to the " / sys / user" path), and automatically encapsulate the basic interfaces such as getById (query by primary key), list (list query), save (add), update (modify), remove (delete) according to the Service layer methods. Each interface adds the @ApiOperation annotation (in the Swagger scenario) to describe the interface function, and at the same time preset the logic for receiving request parameters and encapsulating response results.

[0036] The entire rendering process requires no manual intervention. The template engine will automatically generate the code line by line according to the template structure and data binding relationship. The generated code will fully comply with Java coding standards and the style requirements of the selected template.

[0037] Step S5: Output the full-layer Java code generated in step S4 according to the output configuration in step S1 in a specified manner. The output methods include local file output, code preview, and version control integration to meet the usage needs of different scenarios.

[0038] Specifically, during local file output, the system automatically creates the corresponding package structure (e.g., com.xxx.entity.sys) in the target directory according to the multi-module path configured in step S1, and writes the code files of each level to the corresponding directory. The file naming strictly follows Java naming conventions (e.g., the Entity class is named SysUser.java). The code preview function supports real-time display of the generated code content of each level in a visual interface. The interface provides functions such as code highlighting, line number display, copying, and downloading. Users can quickly verify whether the code meets expectations. If there are any problems, they can go back to adjust the configuration or template and regenerate. The version control integration function is compatible with mainstream version control systems such as Git. If the project has been integrated with Git, the system will automatically detect the local repository status. When using incremental mode for output, it will automatically ignore the code files that already exist in the repository and only add the newly added code files to the staging area, prompting the user to commit. This effectively avoids overwriting manually modified business logic code and ensures the security of version control.

[0039] As one implementation, after generating code in step S4, this method also includes syntax validation and dependency processing. The syntax validation integrates a Java syntax validator (such as Checkstyle) to perform syntax checks on the generated code. If errors are found (such as variables not being replaced due to template syntax errors), the user is prompted to correct the template in real time. The dependency processing automatically identifies the dependencies required to generate the code (such as Lombok dependencies and MyBatis-Plus dependencies), generates dependency configuration fragments in pom.xml (Maven) or build.gradle (Gradle), and prompts the user to add them.

[0040] Example 2: This embodiment provides a database table structure reverse engineering code generation system, such as... Figure 2 As shown, it includes: a requirement input layer, a template customization layer, a parsing layer, a code generation layer, and an output layer. The workflow of each module is as follows: The requirement input layer is used to receive user configuration parameters, which include database configuration, table selection configuration, output configuration, and technology stack adaptation configuration. The template customization layer allows users to use templates selected from a pre-set template library or user-defined templates. The parsing layer parses the metadata of the relational database table structure and implements the mapping between database field types and object-oriented programming language types to obtain standardized metadata of the table structure. The code generation layer binds the standardized metadata of the parsed table structure with the variable placeholders of the template selected in step S2, and calls the template engine to render and generate code. The output layer outputs the generated code in a specified manner.

[0041] The database table structure reverse engineering code generation system described above is used to execute the database table structure reverse engineering code generation method provided in Example 1.

[0042] Example 3: This embodiment takes "generating MyBatis-Plus+Lombok style code for the sys_user table" as an example to explain in detail the reverse engineering code generation and execution process of this invention. The specific steps are as follows: The first step involves the user completing various configurations at the requirement input layer. The database configuration is as follows: connection address jdbc:mysql: / / localhost:3306 / test_db, username root, password 123456; target table is selected as sys_user; output path is set to src / main / java / com / xxx / , with clearly defined paths for each layer of code: Entity layer code is written to the entity / sys directory, Mapper layer code to the mapper / sys directory, Service layer code to the service / sys directory, and Controller layer code to the controller / sys directory; the technology stack is specified as MyBatis-Plus+Lombok+Swagger; and the built-in "MP+Lombok template" is selected.

[0043] The second step involves the parsing layer performing metadata parsing based on the above configuration. The parsing layer retrieves the complete metadata of the `sys_user` table by querying the MySQL system table. The field list includes: `id` (data type: bigint, primary key), `username` (data type: varchar(50), not null), `password` (data type: varchar(100)), `create_time` (data type: datetime), and `status` (data type: tinyint(1), default value: 1). Simultaneously, the parsing layer performs the conversion according to preset type mapping rules. Specifically, `id` maps to `Long`, `username` to `String`, `password` to `String`, `create_time` to `LocalDateTime`, and `status` to `Boolean`.

[0044] The third step involves the code generation layer performing template rendering and full-layer code generation. Based on the standardized metadata output by the parsing layer, and combined with the selected "MP+Lombok template," the template engine is invoked to complete the code rendering for each layer. The specific generated results are as follows: The Entity layer generates SysUser.java, which integrates Lombok's @Data annotation, MyBatis-Plus's @TableName("sys_user") annotation, and Swagger's @ApiModelProperty annotation; the Mapper layer generates SysUserMapper.java, whose interface inherits from MyBatis-Plus's BaseMapper. <sysuser>The interface and Service layer generate two types of files, one inheriting from IService. <sysuser>The SysUserService interface, and the ServiceImpl inheriting interface.<SysUserMapper, SysUser> The SysUserServiceImpl implementation class is generated in the Controller layer; SysUserController.java is generated, which is annotated with @RestController and @RequestMapping(" / sys / user"), and has built-in basic interfaces getById, list, save, update, and remove, and each interface integrates Swagger's @ApiOperation annotation.

[0045] The fourth step is for the output layer to complete the code output. Following the paths configured in the input layer, the output layer writes the code files for the four layers—Entity, Mapper, Service, and Controller—to their respective directories. This completes the entire reverse engineering code generation process.

[0046] Regarding the invention's objective of "generating full-level Java code from MySQL tables with customization support," there are three potential alternatives, but each has significant drawbacks and cannot completely replace the technical solution of this invention, as detailed below: Solution 1 is an annotation-driven code generation approach. It involves the user manually writing Entity classes and adding custom annotations such as `@GenerateService` and `@GenerateController`. An annotation processor then scans these annotations during compilation to generate the corresponding Service and Controller layer code. The core difference between this solution and the present invention lies in the input source. The present invention uses a reverse engineering model "from database to code," while Solution 1 uses a forward generation model "from Entity to code." Solution 1's advantages include flexible annotation configuration, the ability to generate code for individual classes, and integration into the compilation process without requiring additional tools. However, its disadvantages are also significant: users must manually write Entity classes, failing to reduce the repetitive work in the "from database to Entity class" step; it does not support batch code generation from multiple tables, resulting in low efficiency in multi-table scenarios; and template customization requires developing a dedicated annotation processor, demanding high development skills from users and creating a high customization barrier.

[0047] Solution 2 is a code generation based on configuration files. It works by providing an XML or YAML configuration file where the user defines the mapping rules between tables and code, including field mapping relationships and template paths. The tool then reads the rules from the configuration file, queries database metadata, and generates the code. The main difference between this solution and the present invention lies in the interaction method. The present invention uses a visual interface for configuration input and template customization, while Solution 2 defines all generation rules through configuration files. Solution 2 has the advantage of version-manageable configuration files, facilitating internal team sharing, and it does not rely on a visual interface, supporting command-line execution. However, this solution has significant drawbacks: the configuration file writing process is cumbersome; for example, when configuring multiple tables, mapping rules need to be repeatedly written, which can easily lead to configuration errors; template customization requires modifying template paths and variable definitions in the configuration file, making the operation unintuitive; and it does not support real-time preview of the generated results, requiring repeated modifications and debugging when configuration or template issues arise, resulting in high debugging costs.

[0048] Solution 3 is code generation based on IDE plugins. It involves developing plugins adapted for specific IDEs such as IntelliJ and Eclipse, integrating these plugins into the IDE, and allowing users to configure database connections and target table information through the plugin interface. The plugin then calls the IDE's code generation API to generate the code. The difference between this solution and the present invention lies in the deployment environment. The present invention is an independent tool that supports cross-IDE use, while Solution 3 depends on a specific IDE and cannot be deployed across environments. The advantages of Solution 3 are deep integration with the IDE, allowing the generated code to be directly associated with the current development project without requiring manual configuration of the code output path; it also supports calling the IDE's syntax checking function, allowing for direct compilation after code generation. However, its disadvantages are also significant: it has a strong dependency on the IDE environment (e.g., the IntelliJ plugin cannot be used in Eclipse, resulting in poor cross-environment compatibility); plugin development and maintenance costs are high, requiring continuous adaptation to different IDE version updates; and template customization requires modifying the plugin source code, which is beyond the capabilities of ordinary users, making customization extremely difficult.

[0049] A comprehensive analysis of the above alternatives reveals that none of them can simultaneously meet the core requirements of this invention: "reverse engineering, highly customized templates, low-barrier adaptation, and full-layer code generation." Specifically, Solution 1 requires manually writing Entity classes, failing to address the repetitive work involved in mapping data from the database to Entity classes; Solution 2 relies on cumbersome configuration file writing, resulting in poor operational efficiency and intuitiveness; and Solution 3 depends on a specific IDE and has a high barrier to template customization. Therefore, the technical solution of this invention is currently the only optimal solution that comprehensively addresses the pain points of existing technologies.

[0050] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed in this application can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0051] In the embodiments provided in this application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0052] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0053] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.

[0054] The implementation of all or part of the processes in the methods of the above embodiments can also be accomplished by a computer program product. When the computer program product is run on a terminal device, the terminal device can implement the steps in the various method embodiments described above.

[0055] The embodiments described above are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.< / sysuser> < / sysuser>

Claims

1. A database table structure reverse engineering code generation method, characterized by, The method comprises the following steps: Step S1: receiving user configuration parameters, the user configuration parameters comprising database configuration, table selection configuration, output configuration and technology stack adaptation configuration; Step S2: using a template selected from a preset template library or a user-defined template; Step S3: parsing relational database table structure metadata and realizing mapping of database field types and object-oriented programming language types to obtain table structure standardized metadata; Step S4: binding the parsed table structure standardized metadata and variable placeholders of the template selected in step S2, and calling a template engine to render and generate code; Step S5: outputting the generated code in a specified manner.

2. The database table structure reverse engineering code generation method of claim 1, wherein, In step S1, the database configuration comprises a database connection address, a port, a username, a password and a database name; the table selection configuration comprises a target table of the generated code; the output configuration comprises a code generation path and a code coverage strategy; and the technology stack adaptation configuration comprises a specified target technology stack, whether to integrate specified framework required annotations, whether to integrate data verification required annotations and whether to generate interface document required annotations.

3. The database table structure reverse engineering code generation method of claim 1, wherein, The relational database is specifically a MySQL database, and the object-oriented programming language is specifically Java language.

4. The database table structure reverse engineering code generation method of claim 3, wherein, In step S2, the user-defined template mode is compatible with various template engines including Freemarker and Thymeleaf, and has uniformly defined template variables with semantics and names, the template variables corresponding to table structure core information including a table name variable, a field name variable, a Java field type variable and a field annotation variable.

5. The database table structure reverse engineering code generation method of claim 3, wherein, In step S3, the parsing of the relational database table structure metadata comprises: obtaining target table metadata by querying a MySQL system table, the metadata comprising a table name, table annotation, field name, field type, field length, whether a primary key, whether not null, default value and field annotation; the mapping of the database field types and the object-oriented programming language types allows user-defined mapping rules; and the parsing layer can also identify primary keys, index information and foreign key associations of the table, the primary keys comprising single primary keys and joint primary keys.

6. The database table structure reverse engineering code generation method of claim 5, wherein, Step S3 further comprises identifying primary keys, index information and foreign key associations of the table, and automatically adding ORM mapping annotations when generating code based on the identification results.

7. The database table structure reverse engineering code generation method of claim 3, wherein, In step S4, the calling of the template engine to render and generate code comprises: calling a preset template engine, and respectively rendering and generating complete code texts completely matching the template style and structure according to the selected or user-defined corresponding hierarchical templates.

8. The database table structure reverse engineering code generation method of claim 3, wherein, After step S4, the method further comprises performing syntax checking and dependency processing on the generated code; the syntax checking comprises integrating a Java syntax checker to perform syntax checking on the generated code, and if there is an error, prompting the user to correct the template in real time; the dependency processing comprises automatically identifying dependencies required by the generated code, generating corresponding dependency configuration fragments and prompting the user to add.

9. The database table structure reverse engineering code generation method of claim 3, wherein, In step S5, the output code includes local file output, previewing the generated code in the visualization interface, and version control integration that automatically ignores existing code files and only submits new code files when the project is accessed to Git.

10. A database table structure reverse engineering code generation system, characterized by, Comprise: a requirement input layer for receiving user configuration parameters including database configuration, table selection configuration, output configuration, and technology stack adaptation configuration; a template customization layer that uses a template selected from a preset template library or a user-defined template; a parsing layer that parses relational database table structure metadata and implements mapping between database field types and object-oriented programming language types to obtain table structure standardized metadata; a code generation layer that binds the parsed table structure standardized metadata with variable placeholders of the selected template in step S2 and calls a template engine to render and generate code; an output layer that outputs the generated code in a specified manner.