Code generation method and device, equipment and storage medium

By receiving user needs, using technologies such as SpringBoot, Java, Vue.js and MyBatis-Plus to generate front-end and back-end code, solving the problem that existing tools cannot support multi-data sources and cross-frame compatibility, achieving highly customized automatic code generation, and improving development efficiency and code quality.

CN120406923APending Publication Date: 2025-08-01SHENZHEN CASTEL INTELLIGENT TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510359058.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-25
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

Existing code autogenerating tools cannot effectively support multi-data source, cross-frame compatibility, and highly customized requirements, resulting in limitations in dealing with complex requirements.

Method used

By receiving users' code generation requirements, determining the target table structure information and configuration, using SpringBoot, Java, Vue.js, and MyBatis-Plus and other technologies to generate front-end and back-end code files, supporting multi-data sources and cross-frame compatibility, and achieving highly customized code generation.

Benefits of technology

It realizes automatic code generation that supports multi-data sources, cross-frame compatibility and highly customized needs, reducing the work burden of developers and improving development efficiency and code quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120406923A_ABST
    Figure CN120406923A_ABST
Patent Text Reader

Abstract

The invention discloses a code generation method and device, equipment and a storage medium, and relates to the technical field of computers, the method comprises the following steps: receiving a code generation demand of a user; based on the code generation demand, determining target table structure information and target code generation configuration; and generating a front-end code file and a rear-end code file according to the target table structure information based on the target code generation configuration. By means of the method, automatic generation of the front-end code and the rear-end code related to the database table can be achieved, so that the workload of developers is relieved, and the development efficiency and the code quality are effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a code generation method, apparatus, device, and storage medium. Background Art

[0002] As the demand for software products continues to grow, the software development industry is placing a high priority on improving software production efficiency. Code generation tools are often used to shorten the software development process and reduce the human resources required.

[0003] Existing code generation tools typically generate code for a single structure, limited to a single table and a single framework template, leaving them with numerous limitations in handling complex requirements. They also often lack support for multiple data sources, struggle to adapt to templates with different code framework styles, and are unable to support highly customized requirements.

[0004] Therefore, how to achieve automatic code generation that supports multiple data sources, cross-framework compatibility, and highly customized requirements is a technical problem that needs to be solved urgently.

[0005] The above content is only used to assist in understanding the technical solution of this application and does not constitute an admission that the above content is prior art. Summary of the Invention

[0006] The main purpose of this application is to provide a code generation method, apparatus, device and storage medium, aiming to solve the technical problem of how to achieve automatic code generation that supports multiple data sources, cross-framework compatibility and highly customized requirements.

[0007] To achieve the above objectives, the present application proposes a code generation method, which includes:

[0008] Receive user's code generation requirements;

[0009] Based on the code generation requirements, determine target table structure information and target code generation configuration;

[0010] Based on the target code generation configuration, a front-end code file and a back-end code file are generated according to the target table structure information.

[0011] In one embodiment, before the step of receiving the user's code generation requirement, the following steps are included:

[0012] receiving a user's data source configuration parameters, wherein the data source includes a plurality of different types of databases;

[0013] Based on the data source configuration parameters, a target data source is determined, and a connection is established with the target data source.

[0014] In one embodiment, the target code generation configuration includes a front-end code template configuration and a back-end code template configuration. The step of determining the target table structure information and the target code generation configuration based on the code generation requirements includes:

[0015] Parse to obtain table configuration parameters and code style configuration parameters according to the code generation requirements;

[0016] Determine the target table structure information based on the table configuration parameters and the target data source;

[0017] Determine the front-end code template configuration and the back-end code template configuration based on the code style configuration parameters.

[0018] In one embodiment, the step of generating a front-end code file and a back-end code file according to the target table structure information based on the target code generation configuration includes:

[0019] Determine the front-end page code template according to the front-end code template configuration and the target table structure information;

[0020] Generate a front-end code file that matches the target table structure information according to the front-end page code template;

[0021] Connect to the database based on Springboot and the Java language, and generate a back-end code file according to the back-end code template configuration.

[0022] In one embodiment, the step of connecting to the database based on Springboot and the Java language and generating a back-end code file according to the back-end code template configuration includes:

[0023] Connect to the database based on the Java language, connect to the target data source, and obtain the table information of the target data source;

[0024] Obtain the target table field information according to the table information of the target data source and the table configuration parameters;

[0025] Based on Springboot, render the back-end code template according to the target table field information and the back-end code template configuration to generate a back-end code file.

[0026] In one embodiment, the back-end code template configuration includes a back-end code template, a code module configuration, a code storage path, and entity class attributes. The step of rendering the back-end code template according to the target table field information and the back-end code template configuration based on Springboot to generate a back-end code file includes:

[0027] Based on Springboot, render the backend code template according to the target table field information, backend code template, code module configuration, and entity class attributes to generate controller layer, service layer, persistence layer, and entity class code files;

[0028] Construct the backend code file according to the controller layer, service layer, persistence layer, and entity class code files, and store it locally according to the code storage path.

[0029] In one embodiment, the front-end page code template is a front-end code prototype file based on vue2 or vue3;

[0030] The backend code template is a backend code prototype file based on mybatis or mybatis-plus.

[0031] In addition, to achieve the above object, the present application also proposes a code generation device, which includes:

[0032] A receiving module for receiving the user's code generation requirements;

[0033] A configuration determination module for determining target table structure information and target code generation configuration based on the code generation requirements;

[0034] A code generation module for generating front-end code files and backend code files based on the target code generation configuration according to the target table structure information.

[0035] In addition, to achieve the above object, the present application also proposes a code generation device, which includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, and the computer program is configured to implement the steps of the code generation method as described above.

[0036] In addition, to achieve the above object, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium, and when the computer program is executed by a processor, it implements the steps of the code generation method as described above.

[0037] One or more technical solutions proposed by the present application have at least the following technical effects:

[0038] The code generation method, device, device, and storage medium proposed in the embodiments of the present application specifically receive the user's code generation requirements; determine target table structure information and target code generation configuration based on the code generation requirements; and generate front-end code files and backend code files based on the target code generation configuration according to the target table structure information.

[0039] This application receives the code generation requirements of the user; then, according to the code generation requirements, determines the target table to be displayed on the front end, and obtains the target table structure information and the target code generation configuration for instructing the generation of the target code; then determines the relevant code templates according to the target code generation configuration, and renders the relevant code templates in combination with the target table structure information, so as to generate the front-end code file and the back-end code file that match the target table. Through the above solution, this application realizes the automatic generation of the front-end code file and the back-end code file that support multi-data sources, cross-frame compatibility, and highly customized requirements based on the code generation requirements of the user, which can effectively reduce the workload of developers and improve the development efficiency and code quality. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The accompanying drawings here are incorporated into the specification and form a part of this specification, showing the embodiments consistent with this application, and are used together with the specification to explain the principles of this application.

[0041] In order to more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0042] Figure 1 It is a schematic flowchart provided for the first embodiment of the code generation method of this application;

[0043] Figure 2 It is a schematic flowchart provided for the second embodiment of the code generation method of this application;

[0044] Figure 3 It is a schematic flowchart provided for the third embodiment of the code generation method of this application;

[0045] Figure 4 It is a schematic flowchart provided for the fourth embodiment of the code generation method of this application;

[0046] Figure 5 It is a schematic diagram of the module structure of the code generation device in the embodiment of this application;

[0047] Figure 6 It is a schematic diagram of the device structure of the hardware operating environment involved in the code generation method in the embodiment of this application.

[0048] The implementation, functional features, and advantages of the purpose of this application will be further described in combination with the embodiments with reference to the accompanying drawings. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0049] It should be understood that the specific embodiments described here are only used to explain the technical solutions of this application and are not used to limit this application.

[0050] To better understand the technical solution of this application, the following will be described in detail in conjunction with the accompanying drawings of the specification and specific implementation manners.

[0051] The main solution of the embodiments of this application is: receiving the code generation requirements of the user; determining the target table structure information and the target code generation configuration based on the code generation requirements; and generating a front-end code file and a back-end code file according to the target table structure information based on the target code generation configuration.

[0052] Technical terms involved in this application:

[0053] SpringBoot: Spring Boot is a rapid development platform built on the Spring framework, aiming to simplify the initial setup and development process of new Spring applications. By embedding containers such as Tomcat and Jetty, developers can directly run the project without configuring an external server; at the same time, it provides numerous automatic configuration options, reducing cumbersome manual setup work.

[0054] JDBC (Java Database Connectivity): Java Database Connectivity is a set of API interfaces provided by Java for executing SQL statements, which can provide a unified access method for multiple relational databases. In Spring Boot, JDBC is usually used to implement basic operations on the database, such as adding, deleting, modifying, and querying.

[0055] Vue.js: Vue.js is a progressive JavaScript framework focused on building user interfaces. The design concept of Vue is to split complex applications into multiple small components, each of which can be developed and reused independently. This component-based development model improves the maintainability and reuse rate of the code. The core library of Vue only focuses on the view layer, is easy to get started, and is flexible enough to be easily integrated with other libraries or existing projects. Vue 2 and Vue 3 refer to two versions of the Vue.js framework.

[0056] MyBatis: MyBatis is a persistence layer framework that can avoid most of the JDBC code and the work of setting parameters and obtaining result sets. MyBatis can map Java objects and SQL statements, and supports multiple mapping methods, including annotation methods and XML configuration methods, etc., enabling developers to access the database more conveniently. MyBatis can be integrated with common frameworks such as Spring, Spring Boot, and Spring MVC.

[0057] MyBatis-Plus: MyBatis-Plus is an enhanced version of MyBatis. While retaining the original advantages of MyBatis, it adds other useful functions, such as an automatic paging plugin, a code generator, etc. Through these functions, MyBatis-Plus can reduce the workload of developers, thereby improving development efficiency. MyBatis-Plus enables developers to focus on the implementation of business logic rather than repetitive basic coding tasks.

[0058] Existing code generation methods cannot handle the complex requirements of users. They often lack perfect support for multiple data sources, are difficult to adapt to templates of different code framework styles, and cannot support highly customized requirements. Therefore, there is a technical problem of how to achieve automatic code generation that supports multiple data sources, cross-framework compatibility, and highly customized requirements.

[0059] This application provides a solution. By receiving the code generation requirements of users; then, according to the code generation requirements, determining the target table to be displayed on the front end, and obtaining the target table structure information and the target code generation configuration for instructing the generation of target code; then, determining relevant code templates according to the target code generation configuration, and rendering the relevant code templates in combination with the target table structure information, so as to generate a front-end code file and a back-end code file that match the target table. Through the above solution, this application realizes the automatic generation of front-end code files and back-end code files that support multiple data sources, cross-framework compatibility, and highly customized requirements based on the code generation requirements of users, which can effectively reduce the workload of developers and improve development efficiency and code quality.

[0060] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication, and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or a code generation device that can implement the above functions. Hereinafter, taking the code generation device as an example, this embodiment and the following embodiments will be described.

[0061] Based on this, the embodiment of this application provides a code generation method, referring to Figure 1 , Figure 1 which is the flowchart of the first embodiment of the code generation method of this application.

[0062] In this embodiment, the code generation method includes steps S110 to S130:

[0063] Step S110, receiving the code generation requirements of users;

[0064] Step S120, based on the code generation requirements, determining the target table structure information and the target code generation configuration;

[0065] Specifically, the code generation device first needs to receive the user's code generation requirements, and understand information such as the code style configuration required by the user, the target table information to be displayed on the front end, and the associated data source.

[0066] It should be understood that the code generation device can usually provide a visual page for the user to input code generation requirements through multiple form components. Among them, the user's code generation requirements often include information such as selecting a database type, defining a data model or target table structure, specifying the required business logic, selecting front-end and back-end code styles or programming frameworks, data verification requirements, and other code configuration options. Among them, the code in the embodiments of this application refers to code files related to database tables, including front-end code for displaying user interaction pages and back-end code for managing business logic, data storage and retrieval, authentication, and other background services. Among them, the front-end code programming framework can be AngularJS, React.js, Vue.js, etc., and the back-end code programming framework can be Django, Flask, Spring, Springboot, Express.js, etc.

[0067] Then, based on the received code generation requirements, further determine the target table structure information displayed on the front-end user interaction page and the target code generation configuration. Among them, the target table structure information is based on the specific layout and attributes of the data table selected by the user to be displayed, including but not limited to field definitions, multi-table relationship definitions, display rules, sorting or grouping requirements, operation permissions, etc.

[0068] The target code generation configuration refers to a series of code file construction settings and technical selections necessary to implement the above target table structure information, including code programming framework selection, environment variable configuration, security policy configuration, code file module configuration, specified code templates, etc.

[0069] Step S130, based on the target code generation configuration, generate a front-end code file and a back-end code file according to the target table structure information.

[0070] Specifically, the code generation device selects programming frameworks, configures environment variables, security policies, and code file modules according to the target code generation configuration, and uses a preset code generation algorithm to customize the rendering of a specified code template, thereby obtaining front-end and back-end code files customized according to user requirements. The preset code generation algorithm is a related algorithm for automatically generating code pre-set by relevant developers, which can automatically generate front-end and back-end code files that conform to the target code generation configuration by parsing a configuration file (such as an XML (Extensible Markup Language) file) containing the target code generation configuration).

[0071] Furthermore, to achieve automatic code generation that supports multiple data sources, the code generation device can pre-configure multiple required databases. Therefore, before step S110 above, it includes A01 to A02:

[0072] Step A01, receiving the data source configuration parameters of the user, where the data source includes multiple databases of different types;

[0073] Step A02, determining the target data source based on the data source configuration parameters and establishing a connection with the target data source.

[0074] It should be noted that the data source configuration parameters include the driver class name, the Uniform Resource Locator (URL) of the data source, the user name, the password, etc. The data source can be multiple databases of different types, such as any combination of oracle, mysql, and sqlServer databases. It should be understood that the data source configuration parameters can also only include the relevant configuration parameters of one database.

[0075] Among them, the driver class name refers to the fully qualified class name of the JDBC driver used to interact with a specific type of database. For example, for the mysql database, the driver class name is com.mysql.cj.jdbc.Driver; for the oracle database, it may be oracle.jdbc.driver.OracleDriver. The URL defines the network address used to access the database instance.

[0076] Specifically, the code generation device first determines the data source to be connected, that is, the target data source, through the URL by receiving the data source configuration parameters of the user. Then, based on parameters such as the user and password in the data source configuration parameters, a connection is established with the target data source to facilitate subsequent generation of the data required for the target table using the data in the target data source.

[0077] This embodiment provides a code generation method, which receives the code generation requirements of a user; determines target table structure information and target code generation configuration based on the code generation requirements; and generates a front-end code file and a back-end code file according to the target table structure information based on the target code generation configuration.

[0078] Through the above solution, this embodiment receives the code generation requirements of a user; then determines the target table to be displayed on the front end according to the code generation requirements, obtains the target table structure information, and the target code generation configuration for instructing the generation of target code; then determines relevant code templates according to the target code generation configuration, and renders the relevant code templates in combination with the target table structure information, so as to generate a front-end code file and a back-end code file that match the target table. Through the above solution, this application realizes the automatic generation of front-end code files and back-end code files that support multi-data sources, cross-framework compatibility, and highly customized requirements based on the code generation requirements of users, which can effectively reduce the workload of developers and improve development efficiency and code quality.

[0079] Based on the first embodiment of this application, in the second embodiment of this application, the same or similar content as the above-mentioned first embodiment can be referred to the above introduction and will not be repeated hereinafter. On this basis, the target code generation configuration includes a front-end code template configuration and a back-end code template configuration. Please refer to Figure 2 , and the step S120 further includes steps S210 to S230:

[0080] Step S210, parse the table configuration parameters and code style configuration parameters according to the code generation requirements;

[0081] Specifically, first, the code generation device needs to parse the received code generation requirements to obtain the table configuration parameters and code style configuration parameters. Among them, the table configuration parameters refer to the structural characteristics used to describe the target table, including but not limited to the table name, table field list, table field dependency relationship, primary key, foreign key, and index in the table, table control name and content, data dictionary for configuring table controls, data verification requirements, etc.

[0082] The code style configuration parameters determine the form and format of the finally generated code, including front-end code style configuration parameters and back-end code style configuration parameters. Among them, the front-end code style configuration parameters include the selection of programming frameworks, and the back-end code style configuration parameters include but not limited to the selection of programming frameworks, security policy configuration, naming conventions and attribute regulations for elements such as variables, functions, and classes, and code file module configuration.

[0083] Step S220, determine the target table structure information based on the table configuration parameters and the target data source;

[0084] Specifically, the code generation device obtains information of existing tables from the target data source, including column names, data types, constraint conditions, etc. Then, according to the table field dependency relationship in the parsed table configuration parameters, it searches for metadata that has a dependency relationship with the target table field list, so as to determine the data display logic of the target table list and the constraint conditions of the target table (such as non-null, default value, unique value, etc.). Then, combined with the table name, table field list, table control name and content, other table operation functions, etc. in the table configuration parameters, it comprehensively determines the structure information of the target table.

[0085] Step S230, determine the front-end code template configuration and the back-end code template configuration based on the code style configuration parameters.

[0086] Finally, according to the programming framework selection in the front-end code style configuration parameters, determine the front-end page code template type, such as the front-end code prototype file based on vue2, vue3 or react, so as to determine the front-end code template configuration. Among them, the front-end code prototype file based on vue2 or vue3 includes the code templates for front-end single-table data processing operations pre-built by developers, such as data processing operations such as query, add, modify, delete, etc., and the code templates for front-end master-slave table data processing operations.

[0087] According to the programming framework selection, security policy configuration, naming conventions and attribute regulations of elements such as variables, functions and classes, code file module configuration, code file function naming and other parameters in the back-end code style configuration parameters, so as to determine the back-end code template configuration.

[0088] This embodiment provides a code generation method. By receiving the data source configuration parameters of the user, where the data source includes at least any one of oracle, mysql, and sqlServer databases; based on the data source configuration parameters, determine the target data source and establish a connection with the target data source; according to the code generation requirements, parse to obtain the table configuration parameters and the code style configuration parameters; based on the table configuration parameters and the target data source, determine the target table structure information; based on the code style configuration parameters, determine the front-end code template configuration and the back-end code template configuration; based on the target code generation configuration, generate the front-end code file and the back-end code file according to the target table structure information.

[0089] In this embodiment, through the above solution, the code generation requirements are first parsed to obtain table configuration parameters and code style configuration parameters. Then, according to the table configuration parameters and the target data source, the target table structure information is determined. According to the code style configuration parameters, the front-end code template configuration and the back-end code template configuration are determined, so that subsequently, according to the front-end code template configuration and the back-end code template configuration, Springboot and the Java language are combined to connect to the database, realizing the generation of automated front-end code files and back-end code files, thereby reducing the workload of developers and improving development efficiency and code quality.

[0090] Based on the second embodiment of the present application, in the third embodiment of the present application, the same or similar content as in the above-mentioned second embodiment can be referred to the above introduction and will not be repeated hereinafter. On this basis, please refer to Figure 3 , the step S130 includes steps S310 to S330:

[0091] Step S310, determine the front-end page code template according to the front-end code template configuration and the target table structure information;

[0092] Step S320, generate a front-end code file that matches the target table structure information according to the front-end page code template;

[0093] Specifically, in this embodiment, the front-end page code template is preferably a front-end code prototype file based on vue2 or vue3.

[0094] The code generation device first determines, according to the target table structure information, whether the data processing type required for displaying the target table on the front end is a single-table data processing operation or a master-slave table data processing operation. Then, according to the type of the front-end page code template pointed to by the front-end code template configuration, the front-end page code template to be rendered is selected from a plurality of pre-constructed front-end page code templates. It should be understood that the front-end page code template should include the logic of front-end data display.

[0095] Then, according to the field names, field contents, table control names, and contents included in the target table structure information, they are filled into the corresponding placeholder positions in the front-end page code template, and corresponding rules are added to the front-end page code template according to the data types, constraint conditions, and data verification requirements included in the target table structure information, realizing the rendering operation of the front-end page code template, and then generating a front-end code file that matches the target table structure information and conforms to the coding specifications of the coding framework, so as to reduce the work pressure of developers and improve development efficiency and code quality.

[0096] Step S330: Connect to the database based on Springboot and the Java language, and generate a backend code file according to the configuration of the backend code template.

[0097] Specifically, utilize the auto-configuration function of the Spring Boot framework to quickly build a Java application, and combine it with the standard database access technology of JDBC. Determine the generation logic of the target table field data according to the target table structure information, and then render the backend code template correspondingly according to the backend code template configuration to generate a backend code file driven by the target table data, so as to facilitate interaction with the database and provide API (Application Programming Interface) services.

[0098] In a feasible implementation manner, step S330 may include steps B01 to B03:

[0099] Step B01: Connect to the database based on the Java language, connect to the target data source, and obtain the table information of the target data source.

[0100] Step B02: Obtain the target table field information according to the table information of the target data source and the table configuration parameters.

[0101] In order to generate a backend code file driven by the target table data and implement the data processing operation of the function page associated with the front-end code file, the code generation file first needs to utilize the standard database access technology of JDBC, use the preset standard SQL statements to implement the access of multiple data sources, and obtain all the table information from the target data source, including table names, column names, data types, constraint conditions, primary keys, index relationships, etc. The preset standard SQL statements refer to the SQL statements for implementing basic data processing operations, such as querying, deleting, adding, modifying, etc.

[0102] Then, according to the table field dependency relationship in the table information of the target data source and the table configuration parameters, find the associated tables that have a dependency relationship with the target table field list, and query the relevant information of the target table fields, including field names, data types of fields, field constraint conditions, field dependency relationships, etc.

[0103] Step B03: Based on Springboot, render the backend code template according to the target table field information and the backend code template configuration to generate a backend code file.

[0104] Specifically, under the Springboot framework, based on the target table field information, determine the generation logic of all field contents in the target table, and in combination with the backend code template configuration, perform dynamic filling on the backend code template to render the backend code template, thereby generating a backend code file driven by the target table data and matching the frontend code file.

[0105] Through the above solution, this embodiment generates a frontend code file that matches the target table structure information through the frontend code template configuration and the target table structure information; connects to the database according to Springboot and the Java language, and generates a backend code file according to the backend code template configuration, realizing the automatic generation of frontend and backend code files that support multiple data sources and highly customized requirements, which can effectively reduce the workload of developers and improve development efficiency and code quality.

[0106] Based on the first embodiment and / or the second embodiment and / or the third embodiment of the present application, in the fourth embodiment of the present application, the content that is the same as or similar to the above-mentioned embodiment one, embodiment two, and / or embodiment three can be referred to the above introduction and will not be elaborated hereinafter. On this basis, the backend code template configuration includes a backend code template, a code module configuration, a code storage path, and entity class attributes. Please refer to Figure 4 , and the step B03 includes steps S410 to S420:

[0107] Step S410, based on Springboot, render the backend code template according to the target table field information, the backend code template, the code module configuration, and the entity class attributes to generate code files for the control layer, business layer, persistence layer, and entity class;

[0108] Step S420, construct the backend code file according to the code files of the control layer, business layer, persistence layer, and entity class, and store it locally according to the code storage path.

[0109] Specifically, in this embodiment, the backend code template is preferably a backend code prototype file based on mybatis or mybatis-plus.

[0110] Under the Springboot framework, combined with the semi-automatic object-relational mapping capabilities of mybatis or mybatis-plus, realize the automatic generation of corresponding DAO layer interfaces, entity classes, mapper mapping files, etc. according to the target table structure, and construct the persistence layer and entity class code files.

[0111] Specifically, according to the code module configuration, including the code file module name, function name, and entity class attribute configuration, including attribute type regulations, naming conventions, etc., in combination with the target table field information, render the selected pre-built back-end code template based on MyBatis or MyBatis-Plus to automatically generate entity class, persistence layer, service class, and controller class code files.

[0112] Among them, the service class code file is a business layer code file used to implement specific business logics; the controller class code file is a control layer code file responsible for receiving HTTP requests from the front end and forwarding them to the corresponding service layer for processing; the persistence layer code file is responsible for interacting with the database or other forms of data storage media and performing database access operations such as insert, update, delete, and query; the entity class code file is used to implement the mapping with the table structure in the relational database.

[0113] It should be understood that for functions such as single-table query, addition, modification, and deletion implemented in the front-end page code template, the corresponding back-end code template can be a pre-built back-end code template based on MyBatis or MyBatis-Plus that can implement the above functions.

[0114] Finally, according to the automatically generated control layer, business layer, persistence layer, and entity class code files, construct a back-end code file driven by the target table data and matching the front-end code file, and store the back-end code file locally according to the code storage path.

[0115] Through the above solution, in the Springboot framework, according to the target table field information, back-end code template, code module configuration, and entity class attributes, this embodiment automatically generates control layer, business layer, persistence layer, and entity class code files, thereby constructing a back-end code file based on user requirements, realizing cross-framework compatibility and automatic generation of front-end and back-end code files that meet highly customized requirements, which can effectively reduce the workload of developers and improve development efficiency and code quality.

[0116] This application also provides a code generation device. Please refer to Figure 5 , the code generation device includes:

[0117] A receiving module 10 for receiving the user's code generation requirements;

[0118] A configuration determination module 20 for determining the target table structure information and target code generation configuration based on the code generation requirements;

[0119] The code generation module 30 is configured to generate a front-end code file and a back-end code file based on the target code generation configuration and the target table structure information.

[0120] The code generation device provided in this application adopts the code generation method in the above embodiment, and can solve the technical problem of how to realize automatic code generation that supports multiple data sources, cross-frame compatibility, and highly customized requirements. Compared with the prior art, the beneficial effects of the code generation device provided in this application are the same as those of the code generation method provided in the above embodiment, and other technical features in the code generation device are the same as those disclosed in the method of the above embodiment, and will not be elaborated here.

[0121] This application provides a code generation device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the code generation method in the above-mentioned first embodiment.

[0122] Next, refer to Figure 6 , which shows a schematic structural diagram of a code generation device suitable for implementing the embodiments of this application. The code generation device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The code generation device shown is only an example and should not impose any limitations on the functions and usage scope of the embodiments of this application.

[0123] As Figure 6As shown, the code generation device may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which may perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. In the RAM 1004, various programs and data required for the operation of the code generation device are also stored. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems may be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 may allow the code generation device to communicate with other devices wirelessly or wiredly to exchange data. Although the figure shows a code generation device having various systems, it should be understood that it is not required to implement or have all the shown systems. More or fewer systems may be implemented or had alternatively.

[0124] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program codes for performing the methods shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network through the communication device, or installed from the storage device 1003, or installed from the ROM 1002. When the computer program is executed by the processing device 1001, the above functions defined in the methods of the embodiments disclosed in the present application are executed.

[0125] The code generation device provided by the present application, adopting the code generation method in the above embodiments, can solve the technical problem of how to achieve automatic code generation that supports multi-data sources, cross-frame compatibility, and highly customized requirements. Compared with the prior art, the beneficial effects of the code generation device provided by the present application are the same as those of the code generation method provided by the above embodiments, and other technical features in the code generation device are the same as those disclosed in the method of the previous embodiment, and will not be elaborated here.

[0126] It should be understood that each part disclosed in this application can be implemented by hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in a suitable manner in any one or more embodiments or examples.

[0127] As described above, the above is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art within the technical scope disclosed in this application can easily think of changes or substitutions, which should all be covered within the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.

[0128] This application provides a computer-readable storage medium with computer-readable program instructions (i.e., computer programs) stored thereon, and the computer-readable program instructions are used to execute the code generation method in the above embodiments.

[0129] The computer-readable storage medium provided by this application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM) or flash memory, optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this embodiment, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or combined with an instruction execution system, device, or device. The program code contained on the computer-readable storage medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0130] The above computer-readable storage medium can be included in the code generation device; it can also exist separately and not be assembled into the code generation device.

[0131] The above computer-readable storage medium stores one or more programs, which, when executed by a code generation device, cause the code generation device to: receive a user's code generation requirement; determine target table structure information and a target code generation configuration based on the code generation requirement; and generate a front-end code file and a back-end code file according to the target table structure information based on the target code generation configuration.

[0132] Computer program code for performing the operations of this application can be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, and C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).

[0133] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a portion of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0134] The modules described in the embodiments of this application can be implemented in software or in hardware. In some cases, the name of the module does not constitute a limitation on the unit itself.

[0135] The readable storage medium provided by this application is a computer-readable storage medium. The computer-readable storage medium stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned code generation method, and can solve the technical problem of how to achieve automatic code generation that supports multiple data sources, cross-frame compatibility, and highly customized requirements. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by this application are the same as those of the code generation method provided in the above embodiments, and will not be elaborated here.

[0136] The above are only the preferred embodiments of this application, and do not limit the patent scope of this application accordingly. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of this application, or directly or indirectly applied in other related technical fields, shall be included in the patent scope of this application by the same token.

Claims

1. A code generation method, characterized in that, The method includes: Receiving the code generation requirement of the user; Based on the code generation requirement, determining the target table structure information and the target code generation configuration; Based on the target code generation configuration, generating a front-end code file and a back-end code file according to the target table structure information.

2. The method according to claim 1, characterized in that Before the step of receiving the code generation requirement of the user, it includes: Receiving the data source configuration parameters of the user, where the data source includes multiple databases of different types; Based on the data source configuration parameters, determining the target data source and establishing a connection with the target data source.

3. The method according to claim 2, wherein The target code generation configuration includes a front-end code template configuration and a back-end code template configuration. The step of determining the target table structure information and the target code generation configuration based on the code generation requirement includes: According to the code generation requirement, parsing to obtain the table configuration parameters and the code style configuration parameters; Based on the table configuration parameters and the target data source, determining the target table structure information; Based on the code style configuration parameters, determining the front-end code template configuration and the back-end code template configuration.

4. The method according to claim 3, wherein The step of generating a front-end code file and a back-end code file according to the target table structure information based on the target code generation configuration includes: According to the front-end code template configuration and the target table structure information, determining the front-end page code template; According to the front-end page code template, generating a front-end code file that matches the target table structure information; Connecting to the database based on Springboot and the Java language, and generating a back-end code file according to the back-end code template configuration.

5. The method according to claim 4, wherein The step of connecting to the database based on Springboot and the Java language and generating a back-end code file according to the back-end code template configuration includes: Connecting to the database based on the Java language, connecting to the target data source, and obtaining the table information of the target data source; According to the table information of the target data source and the table configuration parameters, obtaining the target table field information; Based on Springboot, rendering the back-end code template according to the target table field information and the back-end code template configuration to generate a back-end code file.

6. The method according to claim 5, wherein The back-end code template configuration includes a back-end code template, a code module configuration, a code storage path, and entity class attributes. The step of rendering the back-end code template according to the target table field information and the back-end code template configuration based on Springboot to generate a back-end code file includes: Based on Springboot, rendering the back-end code template according to the target table field information, the back-end code template, the code module configuration, and the entity class attributes to generate code files for the control layer, the business layer, the persistence layer, and the entity class; According to the code files for the control layer, the business layer, the persistence layer, and the entity class, constructing the back-end code file and storing it locally according to the code storage path.

7. The method according to any one of claims 4 to 6, characterized in that The front-end page code template is a front-end code prototype file based on vue2 or vue3; The backend code template is a backend code prototype file based on MyBatis or MyBatis-Plus.

8. A code generation device, characterized in that, The code generation device includes: a receiving module, configured to receive the code generation requirements of a user; a configuration determination module, configured to determine target table structure information and target code generation configuration based on the code generation requirements; a code generation module, configured to generate a front-end code file and a backend code file according to the target table structure information based on the target code generation configuration.

9. A code generation device, characterized in that, The device includes a memory, a processor, and a computer program stored on the memory and executable on the processor, and the computer program is configured to implement the steps of the code generation method according to any one of claims 1 to 7.

10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium, and when the computer program is executed by a processor, the steps of the code generation method according to any one of claims 1 to 7 are implemented.