Code generation method, device and equipment based on micro-service architecture and medium
By using a code generation method based on a microservice architecture, code is automatically generated, solving the problems of repetitive work for developers and consistency in coding standards, and improving application development efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- QIAN JIN NETWORK INFORMATION TECH SHANGHAI LTD
- Filing Date
- 2024-07-03
- Publication Date
- 2026-06-16
AI Technical Summary
During application development, developers need to write code manually, which leads to repetitive work, is prone to errors, and makes it difficult to follow unified coding standards, thus affecting development efficiency.
By using a code generation method based on microservice architecture, code can be automatically generated using microservice technology, including establishing a database, defining open-source components and business module call relationships, and generating backend code.
It reduces repetitive work for developers, improves application development efficiency, and avoids the inefficiency caused by manually writing code.
Smart Images

Figure CN118747068B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technology, particularly to the field of microservice technology, and especially to a code generation method, apparatus, device and medium based on microservice architecture. Background Technology
[0002] During application development, developers need to write code for each functional module. However, writing code manually is cumbersome and prone to errors. There is also the problem of duplicate coding for different functional modules. In addition, different developers may develop their own coding styles, resulting in code that does not follow a unified coding standard. This consumes a lot of time during subsequent debugging and operation, affecting the development efficiency of the application.
[0003] Therefore, how to reduce repetitive work for developers and improve application development efficiency in application development scenarios is a technical problem that urgently needs to be solved. Summary of the Invention
[0004] In view of this, embodiments of this application provide a code generation method, apparatus, device, medium, and product based on a microservice architecture, which can reduce repetitive work by developers and improve application development efficiency.
[0005] In a first aspect, embodiments of this application provide a code generation method based on a microservice architecture. The method includes: responding to a first user configuration operation, establishing a database for the business system based on multiple data tables configured for the business system; using table fields in the data tables as metadata, creating a mapping relationship between the metadata and class attributes in Java entity classes; responding to a second user configuration operation, defining the various open-source components referenced by the microservice architecture, and the calling relationships between various business service modules in the business system, obtaining microservice architecture template information matching the business system; synchronizing the mapping relationship between metadata and class attributes to the Java memory of the microservice architecture by running a code generation tool, and encoding based on the mapping relationship and the microservice architecture template information to generate backend code for the business system; importing the backend code into an IDE (Intelligent Development Environment), and starting the microservice application of the business system by running the backend code through the IDE.
[0006] In some possible implementations of the first aspect, the second user configuration operation includes a first configuration operation, a second configuration operation, and a third configuration operation, defining the various open-source components referenced by the microservice architecture and the calling relationships between various business service modules in the business system. This includes: in response to the first configuration operation, filtering the target open-source component version number that matches the business system from all open-source component version numbers displayed by the microservice configuration platform to obtain the various open-source components referenced by the microservice architecture; in response to the second configuration operation, determining the dependencies between the various open-source components; and in response to the third configuration operation, determining the calling relationships between the various business service modules.
[0007] In some possible implementations of the first aspect, the engineering structure of the microservice architecture consists of multiple different service layers. These multiple different service layers include at least a request access layer, a backend application BFF layer, a business logic layer, a general business logic layer, and a data access layer. In response to a third configuration operation, the calling relationship between each business service module is determined, including: in response to a third configuration operation, dividing each business service module into different service layers; and defining the calling relationship between each business service module based on the calling relationship between different service layers.
[0008] In some possible implementations of the first aspect, following the response to the second user configuration operation, it further includes: defining, for each business service module, the synchronous invocation Java process and the asynchronous invocation Java process for that business service module.
[0009] In some possible implementations of the first aspect, before running the code generation tool, the method further includes: in response to a third-party user configuration operation, configuring runtime parameters associated with the business system for the code generation tool; wherein the runtime parameters include at least the project type, package prefix, module name, table name, database address, username, password, and code storage directory for each business service module under the microservice architecture, and the project type is divided into no module division, microservice division according to project module structure, microservice division according to business logic layer, and microservice division according to business logic layer and data access layer.
[0010] In some possible implementations of the first aspect, the mapping relationship between metadata and class attributes is synchronized to the Java memory of the microservice architecture by running a code generation tool, including: converting the code generation tool into an executable program by encapsulating the code of the code generation tool into an executable JAR file; calling the code generation tool by running the executable program with one click, and using the code generation tool to read the metadata in the data table, thereby synchronizing the mapping relationship between metadata and class attributes to the Java memory of the microservice architecture.
[0011] In some possible implementations of the first aspect, the business system is a first business system. After obtaining the microservice architecture template information matching the business system, the method further includes: upon obtaining the microservice architecture template information matching the first business system, in response to a fourth user configuration operation, modifying the microservice architecture template information matching the first business system to obtain microservice architecture template information matching the second business system; in response to a fifth user configuration operation, configuring runtime parameters associated with the second business system for the code generation tool; running the code generation tool based on the runtime parameters associated with the second business system, synchronizing the mapping relationship between metadata and class attributes in the database corresponding to the second business system to the Java memory of the microservice architecture, and encoding based on the mapping relationship in the database corresponding to the second business system and the microservice architecture template information of the second business system to generate the backend code of the second business system.
[0012] Secondly, embodiments of this application provide a code generation apparatus based on a microservice architecture. The apparatus includes: a database creation module, used to, in response to a first user configuration operation, establish a database for the business system based on multiple data tables configured for the business system; a creation module, used to use table fields in the data tables as metadata and create a mapping relationship between the metadata and class attributes in Java entity classes; a template configuration module, used to, in response to a second user configuration operation, define the various open-source components referenced by the microservice architecture and the calling relationships between various business service modules in the business system, obtaining microservice architecture template information matching the business system; a code generation module, used to, by running a code generation tool, synchronize the mapping relationship between metadata and class attributes to the Java memory of the microservice architecture, and perform encoding based on the mapping relationship and the microservice architecture template information to generate backend code for the business system; and an application startup module, used to import the backend code into an IDE (Application Development Environment), and start the microservice application of the business system by running the backend code through the IDE.
[0013] In some possible implementations of the second aspect, the second user configuration operation includes a first configuration operation, a second configuration operation, and a third configuration operation. The template configuration module includes: a filtering unit, used in response to the first configuration operation, to filter the target open-source component version number that matches the business system from all open-source component version numbers displayed by the microservice configuration platform, thereby obtaining the various open-source components referenced by the microservice architecture; a determining unit, used in response to the second configuration operation, to determine the dependency relationships between the various open-source components; and the determining unit is also used in response to the third configuration operation to determine the calling relationships between the various business service modules.
[0014] In some possible implementations of the second aspect, the engineering structure of the microservice architecture consists of multiple different service layers, which at least include a request access layer, a backend application BFF layer, a business logic layer, a general business logic layer, and a data access layer. The determining unit is specifically used for: responding to the third configuration operation, dividing each business service module into different service layers; and defining the call relationship between each business service module based on the call relationship between different service layers.
[0015] In some possible implementations of the second aspect, the template configuration module is also used to define, in response to the second user configuration operation, the synchronous and asynchronous Java processes for each business service module.
[0016] Among the possible implementations of the second aspect, there is also a parameter configuration module, which, in response to a third-party user configuration operation, configures the runtime parameters associated with the business system for the code generation tool before running the code generation tool; wherein, the runtime parameters include at least the project type, package prefix, module name, table name, database address, username, password, and code storage directory of each business service module under the microservice architecture, and the project type is divided into no module division, microservice division according to project module structure, microservice division according to business logic layer, and microservice division according to business logic layer and data access layer.
[0017] In some possible implementations of the second aspect, the code generation module is specifically used to: convert the code generation tool into an executable program by encapsulating the code of the code generation tool into an executable jar file; call the code generation tool by running the executable program with one click, and use the code generation tool to read the metadata in the data table, and synchronize the mapping relationship between the metadata and class attributes to the Java memory of the microservice architecture.
[0018] In some possible implementations of the second aspect, the business system is the first business system. After obtaining the microservice architecture template information matching the business system, the system further includes: a new module, used to, in response to the fourth user configuration operation, modify the microservice architecture template information matching the first business system and add microservice architecture template information matching the second business system; a parameter configuration module, used to, in response to the fifth user configuration operation, configure the running parameters associated with the second business system for the code generation tool; and a code generation module, used to run the code generation tool based on the running parameters associated with the second business system, synchronize the mapping relationship between metadata and class attributes in the database corresponding to the second business system to the Java memory of the microservice architecture, and encode the backend code of the second business system based on the mapping relationship in the database corresponding to the second business system and the microservice architecture template information of the second business system.
[0019] Thirdly, embodiments of this application provide an electronic device, including: a processor and a memory storing computer program instructions; the processor executes the computer program instructions to implement the steps of the code generation method based on microservice architecture as described in the first aspect.
[0020] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer program instructions, which, when executed by a processor, implement the steps of the code generation method based on a microservice architecture as described in the first aspect.
[0021] Fifthly, embodiments of this application provide a computer program product stored in a non-volatile storage medium, wherein when the computer program product is executed by a processor, it implements the steps of the code generation method based on a microservice architecture as described in the first aspect.
[0022] In a sixth aspect, embodiments of this application provide a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the steps of the code generation method based on a microservice architecture as described in the first aspect.
[0023] This application provides a code generation method, apparatus, device, medium, and product based on a microservice architecture. Considering that under specific development languages and technical frameworks, aside from differences in the data table structures of various modules within a business system, a large portion of the code structure is identical, microservice technology can be used to automatically generate code to reduce repetitive code. Specifically, through a first user configuration operation, a database matching the business system and the mapping relationship between metadata in the data tables and class attributes in Java entity classes can be established. Through a second user configuration operation, the various open-source components referenced by the microservice architecture under this business system and the calling relationships between various business service modules in the business system can be defined, obtaining microservice architecture template information matching the business system. Based on this, by running the code generation tool, the mapping relationship between metadata and class attributes in the business system can be synchronized to the Java memory of the microservice architecture, and encoding can be performed based on the mapping relationship and the microservice architecture template information to generate the backend code of the business system. Thus, this application can use Java as the development language and microservice technology to complete database modeling. Through automated code generation tools, it can generate code for specified microservice projects, reducing repetitive work for developers, avoiding inefficiency caused by manual coding, and quickly and effectively generating microservice application code, thereby improving application development efficiency. Attached Figure Description
[0024] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings of the embodiments of this application will be briefly described below.
[0025] Figure 1 This is a flowchart illustrating a code generation method based on a microservice architecture provided in an embodiment of this application;
[0026] Figure 2 This is a flowchart illustrating a code generation method based on a microservice architecture provided in another embodiment of this application;
[0027] Figure 3 This is a schematic diagram of the engineering structure of a microservice architecture provided in an embodiment of this application;
[0028] Figure 4 This is a flowchart illustrating a code generation method based on a microservice architecture provided in another embodiment of this application;
[0029] Figure 5 This is a schematic diagram of the structure of a code generation device based on a microservice architecture provided in an embodiment of this application;
[0030] Figure 6 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0031] The principles and spirit of this application will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided to make the principles and spirit of this application clearer and more thorough, enabling those skilled in the art to better understand and implement the principles and spirit of this application. The exemplary embodiments provided herein are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments described herein without inventive effort are within the scope of protection of this application.
[0032] In this document, terms such as first, second, and third are used only to distinguish one entity (or operation) from another, and are not intended to require or imply any order or relationship between these entities (or operations).
[0033] The code generation method based on microservice architecture provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.
[0034] Figure 1This is a flowchart illustrating a code generation method based on a microservice architecture provided in an embodiment of this application. The execution entity of this code generation method based on a microservice architecture can be a server, which can be connected to various business systems and is used to generate corresponding backend code for each business system.
[0035] For example, in the context of online recruitment, each business system may include the B-end and C-end corresponding to the online recruitment platform. The B-end may include the online talent recruitment system, online application recruitment system, training system, etc. used by recruiting users, while the C-end may include the job search system for fresh graduates, online application job search system, job recommendation system, etc. used by job seekers.
[0036] The following example, using a server as the execution entity in a code generation method based on a microservice architecture, illustrates the code generation method for a microservice architecture as described in this application. It should be noted that the aforementioned execution entity and application scenario do not constitute a limitation on this application.
[0037] like Figure 1 As shown, the code generation method based on microservice architecture provided in this application embodiment may include steps 110-150.
[0038] Step 110: In response to the first user configuration operation, establish the database of the business system based on the multiple data tables configured for the business system;
[0039] Step 120: Use the table fields in the data table as metadata, and create a mapping relationship between the metadata and the class attributes in the Java entity class;
[0040] Step 130: In response to the second user configuration operation, define the various open-source components referenced by the microservice architecture and the calling relationships between various business service modules in the business system, and obtain microservice architecture template information that matches the business system.
[0041] Step 140: By running the code generation tool, the mapping relationship between metadata and class attributes is synchronized to the Java memory of the microservice architecture, and the backend code of the business system is generated based on the mapping relationship and the microservice architecture template information.
[0042] Step 150: Import the backend code into the programming IDE and run the backend code through the IDE to start the microservice application of the business system.
[0043] The code generation method based on microservice architecture provided in this application takes into account that, under specific development languages and technical frameworks, apart from the different data table structures of each module in the business system, a large part of the code structure is the same. Therefore, to reduce the amount of duplicate code, microservice technology can be used to automatically generate code. Specifically, through a first user configuration operation, a database matching the business system and the mapping relationship between metadata in the data tables and class attributes in Java entity classes can be established. Through a second user configuration operation, the various open-source components referenced by the microservice architecture under the business system and the calling relationships between various business service modules in the business system can be defined, obtaining microservice architecture template information matching the business system. Based on this, by running the code generation tool, the mapping relationship between metadata and class attributes in the business system can be synchronized to the Java memory of the microservice architecture, and the backend code of the business system can be generated based on the mapping relationship and the microservice architecture template information. Thus, this application can use Java as the development language and microservice technology to complete database modeling. Through automated code generation tools, it can generate code for specified microservice projects, reducing repetitive work for developers, avoiding inefficiency caused by manual coding, and quickly and effectively generating microservice application code, thereby improving application development efficiency.
[0044] The specific implementation of the above steps will be described in detail below with reference to specific embodiments.
[0045] In step 110, in response to the first user configuration operation, a database for the business system is established based on multiple data tables configured for the business system.
[0046] In step 110, the business system may include various business service modules, which are functional modules. For example, in an e-commerce system, these might include an identity authentication module, an order module, and a product module; in a recruitment system, they might include a resume module and a job matching module. This application does not specifically limit the scope of these modules. The subsequent backend code of the business system is generated based on the database model, i.e., the mapping relationship, conforming to the software engineering principle of modeling before coding.
[0047] The first user configuration operation is used to create a corresponding data table for each business service module. Therefore, the multiple data tables include at least one data table corresponding to each business service module. This data table contains table structure information such as the field name, field type, whether it is required, and default value of multiple table fields.
[0048] For example, the first user configuration operation can be a code writing operation, such as building a data table by entering the following code:
[0049] The field name `id` is bigint(20) NOT NULL COMMENT 'Primary key'
[0050] `ctmid` is bigint(20) NOT NULL COMMENT 'Network Talent Member Id'
[0051] `hruid` is bigint(20) NOT NULL COMMENT 'Network Talent User Id'
[0052] `ep_name` is varchar(300) NOT NULL DEFAULT” COMMENT 'Full name of the enterprise'
[0053] `ep_cert_no` is varchar(50) NOT NULL DEFAULT” COMMENT 'Unified social credit code or business license registration number'
[0054] `certify_status` is varchar(50) NOT NULL DEFAULT” COMMENT 'Certification status'
[0055] `auth_status` is varchar(50) NOT NULL DEFAULT” COMMENT 'Authorization status'
[0056] `step` is tinyint(4) NOT NULL DEFAULT '1' COMMENT 'Certification steps: 1, initialization; 2, data has been initialized; 3, in the process of certification; 4, certification failed (can be re-certified); 5, certification failed (cannot be re-certified); 6, certification successful;'
[0057] In step 120, the table fields in the data table are used as metadata to establish the mapping relationship between the new metadata and the class attributes in the Java entity class.
[0058] In step 120, the first user configuration operation is also used to establish the mapping relationship between the metadata and the class attributes. In Java, class attributes (also known as member variables) are components of a class and are variables directly defined in the class. They are shared among all objects of the class. Class attributes can be global, defined using the static keyword, indicating that the variable belongs to the class rather than any specific instance of the class. The access to class attributes can be through the class name or the object name, depending on the access modifier of the attribute (such as public, private, etc.). Class attributes correspond to the table fields in the data table, and the attribute values of class attributes correspond to the table field records in the data table, that is, the table structure information.
[0059] In step 130, in response to the second user configuration operation, the various open-source components referenced by the microservice architecture and the calling relationships between various business service modules in the business system are defined to obtain microservice architecture template information that matches the business system.
[0060] In step 130, the second user configuration operation is used to select the open source components referenced by the microservice architecture from all open source components and limit the dependency relationship between each business service module, which is the calling relationship.
[0061] In some embodiments of this application, the second user configuration operation includes a first configuration operation, a second configuration operation, and a third configuration operation. In response to the first configuration operation and the second configuration operation, the various open-source components referenced by the microservice architecture are defined. In response to the third configuration operation, the calling relationship between various business service modules in the business system is defined.
[0062] In some embodiments of this application, to avoid dependency conflicts between open-source components that could cause microservice applications to malfunction, Figure 2 This is a flowchart illustrating a code generation method based on a microservice architecture provided in another embodiment of this application. The second user configuration operation may include a first configuration operation, a second configuration operation, and a third configuration operation. The definition of the various open-source components referenced by the microservice architecture and the calling relationships between various business service modules in the business system in step 130 may specifically include steps 210-230.
[0063] Step 210: In response to the first configuration operation, filter the target open source component version number that matches the business system from all open source component version numbers displayed on the microservice configuration platform to obtain the various open source components referenced by the microservice architecture.
[0064] Step 220: In response to the second configuration operation, determine the dependencies between the various open-source components;
[0065] Step 230: In response to the third configuration operation, determine the calling relationship between the various business service modules.
[0066] Specifically, the microservice configuration platform can display the version numbers of all open-source components. The first configuration operation can be a user action to select the version number of a target open-source component. The second configuration operation is used to build a dependency tree for each target open-source component version number; therefore, in response to the second configuration operation, the dependency relationships between various open-source components can be determined. The third configuration operation can be an operation to limit the call relationships between various business service modules through code writing or information filling.
[0067] In this embodiment, by filtering the version numbers of target open-source components, all open-source components and their version numbers referenced by the microservice architecture under the business system can be determined. Since only version numbers are identified, incompatibility issues caused by version number discrepancies can be avoided, ensuring the normal operation of subsequent microservice applications. Furthermore, the open-source components to be integrated can be selected independently through configuration files, allowing for the integration of a wide range of open-source components with high selectivity. Unified dependency management of all open-source components and business service modules facilitates component upgrades, prevents conflicts between JAR dependencies, and improves development efficiency.
[0068] In some embodiments of this application, the engineering structure of a microservice architecture can consist of multiple different service layers. These multiple different service layers at least include a request access layer, a backend application BFF layer, a business logic layer, a general business logic layer, and a data access layer. Step 230 above, in response to the third configuration operation, determines the calling relationship between various business service modules, and may specifically include:
[0069] In response to the third configuration operation, the various business service modules are divided into different service layers;
[0070] Based on the calling relationships between different service layers, the calling relationships between various business service modules are defined.
[0071] Specifically, the microservice configuration platform can display multiple first input boxes associated with different service layers, and the third configuration operation is to fill in the corresponding business service module identifier in each of the multiple first input boxes; or, the microservice configuration platform can display multiple second input boxes associated with each business service module, and the third configuration operation is to fill in the corresponding service layer identifier in each of the multiple second input boxes.
[0072] As an example, such as Figure 3 As shown, the engineering structure of the microservice architecture consists of a terminal display layer, open interfaces, request access layer (Web layer), BFF layer (api-mics), business logic layer (mics), common business logic layer (common-mics), and data access layer (dal-mics). The common business logic layer can transmit data with external interfaces or third-party platforms, and the data access layer obtains data by querying the database DB.
[0073] In this embodiment, the calling relationship between different service layers can be clearly defined through the engineering structure of the microservice architecture. Therefore, it is only necessary to divide each business service module and define the association between the business service module and the service layer to accurately determine the calling relationship between different business service modules. Subsequently, the complete project structure based on the Spring Cloud microservice architecture can be generated using this calling relationship. The microservice application can be run without much additional code modification.
[0074] In some embodiments of this application, after step 130 in response to the second user configuration operation, the following steps may also be included:
[0075] For each business service module, define the synchronous and asynchronous Java processes that call the business service module.
[0076] In step 140, the mapping relationship between metadata and class attributes is synchronized to the Java memory of the microservice architecture by running a code generation tool, and the backend code of the business system is generated based on the mapping relationship and the microservice architecture template information.
[0077] In step 140, by running the code generation tool, the tool can encode backend code for the business system based on the mapping relationships in the business system and the microservice architecture template information that matches the business system. This backend code is microservice code. Developers can set the code storage directory corresponding to the business system. After the backend code of the business system is generated, it can be directly stored as code files in the pre-configured code storage directory.
[0078] In some embodiments of this application, the following steps may be included before running the code generation tool in step 140 above:
[0079] In response to third-party user configuration operations, configure runtime parameters for the code generation tool that are associated with the business system;
[0080] The third user configuration operation can be a code writing operation. The runtime parameters include at least the project type, package prefix, module name, table name, database address, username, password, and code storage directory of each business service module under the microservice architecture. In addition, it can also include the table prefix, driver, custom extension multi-cluster, Spring Boot default method, DruidDataSource data source, etc. The project type can be divided into no module division, microservice division according to project module structure, microservice division according to business logic layer, and microservice division according to business logic layer and data access layer.
[0081] For example, the following is a portion of the code written when configuring runtime parameters through a third-party user configuration operation:
[0082] #Generate code storage directory. If left blank, the default is the current directory; optional.
[0083] projectPath=XXX
[0084] # Package prefix, defaults to com.jobs; the generated code package does not include the module name; optional.
[0085] packageNamePrefx=com.jobs.identity.auth
[0086] #Module name, lowercase, supports underscores or hyphens separating words; required field
[0087] moduleName = identity-auth
[0088] #Note the author's name; optional
[0089] author = dual
[0090] #Table name, multiple fields separated by commas; required fields
[0091] tableNames = aut_str_mark
[0092] #Prefix, this declaration will not include the prefix when generating entity and class files; optional.
[0093] tablePrefix = XXX
[0094] #Database address, required field
[0095] jdbcUrl=XXX
[0096] #Driver, required field
[0097] jdbcDriverName=XXX
[0098] #Username, required field
[0099] jdbcUserName = hrodbadmin
[0100] #Password, required field
[0101] jdbcPassword=XXX
[0102] #Whether to overwrite generated files, 0: yes, 1: no, default value 0, optional
[0103] fileOverride=0
[0104] #MyBatis framework type, 0: MyBatisPlus, 1: Native MyBatis, 2: tk.mybatis; Default is 0; Optional
[0105] mybatisType = 0
[0106] In this embodiment, before running the code generation tool, relevant business system information can be used to configure corresponding running parameters for the tool. This allows the tool to generate backend code compatible with the business system based on the mapping relationships within the business system and the microservice architecture template information matching the business system. Furthermore, each business service module can match different project types according to actual needs, improving the adaptability of the subsequently generated backend code.
[0107] In some embodiments of this application, step 140 above, which synchronizes the mapping relationship between metadata and class attributes to the Java memory of the microservice architecture by running a code generation tool, may include the following steps:
[0108] By packaging the code of the code generation tool into an executable JAR file, the code generation tool is converted into an executable program;
[0109] The executable program is run with one click to call the code generation tool, which then reads the metadata from the data table and synchronizes the mapping between the metadata and class attributes to the Java memory of the microservice architecture.
[0110] Specifically, an executable JAR file is a self-contained Java application stored in a specially configured JAR file that can be executed directly by the Java Virtual Machine (JVM) without prior file extraction or classpath setup. Executable JARs facilitate the distribution and execution of Java applications.
[0111] In this embodiment of the application, the original code generation tool is in the form of a command line. By packaging it into a jar, it is converted into an executable program that can be run with one click. There is no need to extract files or set class paths in advance, which improves its integration level. Moreover, developers can generate code with one click. The operation is simple and improves the efficiency of backend code generation.
[0112] In some embodiments of this application, the aforementioned business system can serve as the first business system, in order to further improve application development efficiency. Figure 4This is a flowchart illustrating a code generation method based on a microservice architecture provided in another embodiment of this application. After obtaining the microservice architecture template information matching the business system in step 140 above, the method may further include steps 410-430.
[0113] Step 410: If the microservice architecture template information matching the first business system is obtained, in response to the fourth user configuration operation, the microservice architecture template information matching the first business system is modified, and the microservice architecture template information matching the second business system is added.
[0114] Step 420: In response to the fifth user configuration operation, configure the runtime parameters associated with the second business system for the code generation tool;
[0115] Step 430: Based on the running parameters associated with the second business system, run the code generation tool to synchronize the mapping relationship between metadata and class attributes in the database corresponding to the second business system to the Java memory of the microservice architecture, and encode the backend code of the second business system based on the mapping relationship in the database corresponding to the second business system and the microservice architecture template information of the second business system.
[0116] Specifically, the microservice architecture template information matching the first business system can be the first microservice architecture template information, and the microservice architecture template information matching the second business system can be the second microservice architecture template information. The fourth user configuration operation is used to make adjustments based on the first microservice architecture template information. Specifically, it can be to adjust the open-source components referenced by the microservice architecture and adjust the call relationship between various business service modules in the first business system to the call relationship between various business service modules in the second business system, thereby obtaining the second microservice architecture template information matching the second business system.
[0117] In some embodiments of this application, before step 430 above, a database of the second business system can be pre-established. This database includes data tables corresponding to each business service module in the second business system. The table fields in the data tables are used as metadata, and a mapping relationship between the metadata and the class attributes in the Java entity class is established to obtain the mapping relationship in the database corresponding to the second business system.
[0118] In this embodiment, after the initial configuration and generation of microservice architecture template information, appropriate modifications can be made based on the characteristics of different business systems to create microservice architectures adapted to each business system, thus obtaining corresponding microservice architecture template information matching the business system. In this way, by appropriately adjusting the microservice architecture template information of the first business system, microservice architecture template information matching other systems can be obtained. Furthermore, the backend code for each business system can be created accordingly using these microservice architecture templates, requiring minimal additional code modifications to run the application. This significantly improves the efficiency of microservice application development for business systems.
[0119] In some embodiments of this application, after obtaining the first microservice architecture template information matching the first business system in step 130, the first microservice architecture template information can be stored in the template library, so that step 410 above can obtain the first microservice architecture template information from the template library.
[0120] Furthermore, the microservice architecture template information of each business system can be uploaded to the template library for storage, making it convenient to retrieve and use when developing microservice applications for other business systems.
[0121] Step 150 involves importing the backend code into the programming IDE and running the backend code through the IDE to start the microservice application of the business system.
[0122] In step 150, the integrated development environment (IDE) is a tool used for software development, providing functions such as code editing, compilation, debugging, and deployment. Specifically, the IDE can convert backend code into an executable program or interpreter, and supports backend development as well as mobile application development. Here, the executable program is a microservice application.
[0123] In some embodiments of this application, the microservice architecture is based on the Spring Boot framework, and the underlying framework of the code generation tool is mybatis-plus-generator.
[0124] In some embodiments of this application, the code generation tool may be AutoGenerator, code-gen, or CodeGenerate ORM.
[0125] It should be noted that the code generation method based on microservice architecture provided in this application embodiment can be implemented in programming languages such as C#, Go, Typescript, and Python, in addition to Java. This application does not make any specific limitations on this.
[0126] Corresponding to the method embodiments of this application, this application also provides a code generation apparatus based on a microservice architecture.
[0127] Figure 5 This is a schematic diagram of the structure of a code generation device based on a microservice architecture provided in an embodiment of this application. Figure 5 As shown, the code generation device 500 based on microservice architecture may include: a library creation module 510, a new creation module 520, a template configuration module 530, and a code generation module 540.
[0128] The system comprises the following modules: a database creation module 510, which, in response to the first user configuration operation, establishes the database of the business system based on multiple data tables configured for the business system; a creation module 520, which uses table fields from the data tables as metadata and establishes a mapping relationship between the metadata and class attributes in the Java entity classes; a template configuration module 530, which, in response to the second user configuration operation, defines the various open-source components referenced by the microservice architecture and the calling relationships between various business service modules in the business system, obtaining microservice architecture template information that matches the business system; a code generation module 540, which, by running a code generation tool, synchronizes the mapping relationship between metadata and class attributes to the Java memory of the microservice architecture, and generates the backend code of the business system based on the mapping relationship and the microservice architecture template information; and an application startup module, which imports the backend code into the programming IDE and starts the microservice application of the business system by running the backend code through the IDE.
[0129] The code generation device based on microservice architecture provided in this application takes into account that, under specific development languages and technical frameworks, apart from the different data table structures of each module in the business system, a large part of the code structure is the same. Therefore, to reduce the amount of duplicate code, microservice technology can be used to automatically generate code. Specifically, through a first user configuration operation, a database matching the business system and the mapping relationship between metadata in the data tables and class attributes in Java entity classes can be established. Through a second user configuration operation, the various open-source components referenced by the microservice architecture under the business system and the calling relationships between various business service modules in the business system can be defined, obtaining microservice architecture template information matching the business system. Based on this, by running the code generation tool, the mapping relationship between metadata and class attributes in the business system can be synchronized to the Java memory of the microservice architecture, and encoding can be performed based on the mapping relationship and the microservice architecture template information to generate the backend code of the business system. Thus, this application can use Java as the development language and microservice technology to complete database modeling. Through automated code generation tools, it can generate code for specified microservice projects, reducing repetitive work for developers, avoiding inefficiency caused by manual coding, and quickly and effectively generating microservice application code, thereby improving application development efficiency.
[0130] In some embodiments of this application, the second user configuration operation includes a first configuration operation, a second configuration operation, and a third configuration operation. The template configuration module 530 includes: a filtering unit, used to filter the target open-source component version number that matches the business system from all open-source component version numbers displayed by the microservice configuration platform in response to the first configuration operation, to obtain each open-source component referenced by the microservice architecture; a determining unit, used to determine the dependency relationship between each open-source component in response to the second configuration operation; and the determining unit is also used to determine the calling relationship between each business service module in response to the third configuration operation.
[0131] In some embodiments of this application, the engineering structure of the microservice architecture consists of multiple different service layers, which at least include a request access layer, a backend application BFF layer, a business logic layer, a general business logic layer, and a data access layer. The determining unit is specifically used for: responding to a third configuration operation, dividing each business service module into different service layers; and defining the call relationship between each business service module based on the call relationship between different service layers.
[0132] In some embodiments of this application, the template configuration module 530 is further configured to, in response to a second user configuration operation, define synchronous and asynchronous Java process calls for each business service module.
[0133] In some embodiments of this application, a parameter configuration module is further included, which, in response to a third-user configuration operation, configures runtime parameters associated with the business system for the code generation tool before running the code generation tool; wherein, the runtime parameters include at least the project type, package prefix, module name, table name, database address, username, password, and code storage directory of each business service module under the microservice architecture, and the project type is divided into no module division, microservice division according to project module structure, microservice division according to business logic layer, and microservice division according to business logic layer and data access layer.
[0134] In some embodiments of this application, the code generation module 540 is specifically used to: encapsulate the code of the code generation tool into an executable jar file, convert the code generation tool into an executable program; call the code generation tool by running the executable program with one click, and use the code generation tool to read the metadata in the data table, and synchronize the mapping relationship between the metadata and class attributes to the Java memory of the microservice architecture.
[0135] In some embodiments of this application, the business system is a first business system. After obtaining the microservice architecture template information matching the business system, the system further includes: a adding module, used to, in response to a fourth user configuration operation, modify the microservice architecture template information matching the first business system to add microservice architecture template information matching the second business system; a parameter configuration module, used to, in response to a fifth user configuration operation, configure the running parameters associated with the second business system for the code generation tool; and a code generation module, used to run the code generation tool based on the running parameters associated with the second business system, synchronize the mapping relationship between metadata and class attributes in the database corresponding to the second business system to the Java memory of the microservice architecture, and encode the backend code of the second business system based on the mapping relationship in the database corresponding to the second business system and the microservice architecture template information of the second business system.
[0136] The code generation device based on microservice architecture provided in this application embodiment can achieve... Figure 1-4 The various processes implemented by the service platform in the method embodiment can achieve the same technical effect, and will not be described again here to avoid repetition.
[0137] Figure 6 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application.
[0138] like Figure 6 As shown, the electronic device 600 includes a memory 601, a processor 602, and a computer program stored in the memory 601 and executable on the processor 602.
[0139] In one example, the processor 602 described above may include a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits that may be configured to implement the embodiments of this application.
[0140] Memory 601 may include read-only memory (ROM), random access memory (RAM), disk storage media device, optical storage media device, flash memory device, electrical, optical, or other physical / tangible memory storage device. Therefore, typically, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the card opening method in the embodiments according to the first aspect of this application.
[0141] The processor 602 runs a computer program corresponding to the executable program code by reading the executable program code stored in the memory 601, so as to implement the card opening method in the embodiment of the first aspect above.
[0142] In some examples, electronic device 600 may also include communication interface 603 and bus 610. For example, Figure 6 As shown, the memory 601, processor 602, and communication interface 603 are connected through bus 610 and complete communication with each other.
[0143] The communication interface 603 is mainly used to enable communication between various modules, devices, units, and / or equipment in the embodiments of this application. Input devices and / or output devices can also be connected through the communication interface 603.
[0144] Bus 610 includes hardware, software, or both, that couples components of electronic device 600 together. For example, and not limitingly, bus 610 may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-E) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 610 may include one or more buses. Although specific buses are described and illustrated in the embodiments of this application, this application considers any suitable bus or interconnection.
[0145] The electronic device provided in this application embodiment is capable of achieving Figure 1-4 The various processes implemented by the electronic device in the method embodiment can achieve the same technical effect, and will not be described again here to avoid repetition.
[0146] In conjunction with the code generation method based on microservice architecture in the above embodiments, this application embodiment can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when these computer program instructions are executed by a processor, they implement the steps of any of the code generation methods based on microservice architecture in the above embodiments.
[0147] Based on the code generation method for microservice architecture described in the above embodiments, this application provides a computer program product for implementation. This (computer) program product is stored in a non-volatile storage medium, and when executed by at least one processor, it implements the steps of any of the code generation methods for microservice architecture described in the above embodiments.
[0148] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled. The processor is used to run programs or instructions to implement the various processes of the above-described microservice architecture-based code generation method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0149] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0150] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.
[0151] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.
[0152] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.
[0153] The aspects of this disclosure have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by special-purpose hardware performing the specified functions or actions, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0154] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.
Claims
1. A code generation method based on a microservice architecture, characterized in that, include: In response to the first user configuration operation, a database of the business system is established based on multiple data tables configured for the business system. The first user configuration operation is used to create a corresponding data table for each business service module. The multiple data tables include at least one data table corresponding to each business service module. Use the table fields in the data table as metadata, and create a new mapping relationship between the metadata and the class attributes in the Java entity class; In response to the second user configuration operation, define the various open-source components referenced by the microservice architecture, as well as the calling relationships between various business service modules in the business system, and obtain microservice architecture template information that matches the business system; Wherein: the second user configuration operation includes a first configuration operation, a second configuration operation, and a third configuration operation. In response to the first configuration operation, the target open-source component version number matching the business system is filtered from all open-source component version numbers displayed on the microservice configuration platform to obtain the various open-source components referenced by the microservice architecture. The engineering structure of the microservice architecture consists of multiple different service layers, which at least include a request access layer, a backend application BFF layer, a business logic layer, a general business logic layer, and a data access layer. In response to the second configuration operation, the dependency relationship between the various open-source components is determined. In response to the third configuration operation, each business service module is divided into the different service layers, and based on the call relationship between the different service layers, the call relationship between the various business service modules is defined to obtain the microservice architecture template information matching the business system. In response to a third user configuration operation, the code generation tool is configured with runtime parameters associated with the business system. The runtime parameters include at least the project type, package prefix, module name, table name, database address, username, password, and code storage directory for each business service module under the microservice architecture. The project type is divided into no module division, microservice division by project module structure, microservice division by business logic layer, and microservice division by business logic layer and data access layer. By running a code generation tool, the mapping relationship between the metadata and the class attributes is synchronized to the Java memory of the microservice architecture, and the backend code of the business system is generated based on the mapping relationship and the microservice architecture template information. Import the backend code into an IDE (Application Development Environment), and run the backend code through the IDE to start the microservice application of the business system.
2. The method according to claim 1, characterized in that, Following the response to the second user configuration operation, the method further includes: For each business service module, define the synchronous and asynchronous Java processes that call the business service module.
3. The method according to claim 1, characterized in that, The step of synchronizing the mapping relationship between the metadata and the class attributes to the Java memory of the microservice architecture by running a code generation tool includes: By packaging the code of the code generation tool into an executable JAR file, the code generation tool is converted into an executable program; The executable program is run with one click to invoke the code generation tool, which then reads the metadata in the data table and synchronizes the mapping relationship between the metadata and the class attributes to the Java memory of the microservice architecture.
4. The method according to claim 1, characterized in that, The business system is a first business system. After obtaining the microservice architecture template information matching the business system, the method further includes: Upon obtaining microservice architecture template information matching the first business system, in response to the fourth user configuration operation, the microservice architecture template information matching the first business system is modified, and microservice architecture template information matching the second business system is added. In response to the fifth user configuration operation, configure the running parameters associated with the second business system for the code generation tool; The code generation tool is run based on the running parameters associated with the second business system. The mapping relationship between the metadata and class attributes in the database corresponding to the second business system is synchronized to the Java memory of the microservice architecture. The backend code of the second business system is generated based on the mapping relationship in the database corresponding to the second business system and the microservice architecture template information of the second business system.
5. A code generation device based on a microservice architecture, characterized in that, include: The database creation module is used to respond to the first user configuration operation and establish the database of the business system based on multiple data tables configured for the business system. The first user configuration operation is used to create a corresponding data table for each business service module. The multiple data tables include at least one data table corresponding to each business service module. Create a new module to use the table fields in the data table as metadata and create a mapping relationship between the metadata and class attributes in the Java entity class; The template configuration module is used to respond to the second user configuration operation, define the various open source components referenced by the microservice architecture, as well as the calling relationship between various business service modules in the business system, and obtain microservice architecture template information that matches the business system; The second user configuration operation includes a first configuration operation, a second configuration operation, and a third configuration operation. The template configuration module is specifically used for: responding to the first configuration operation, filtering the target open-source component version number matching the business system from all open-source component version numbers displayed on the microservice configuration platform to obtain the various open-source components referenced by the microservice architecture; the microservice architecture's engineering structure consists of multiple different service layers, each including at least a request access layer, a backend application BFF layer, a business logic layer, a general business logic layer, and a data access layer; responding to the second configuration operation, determining the dependencies between the various open-source components; and responding to the third configuration operation, dividing each business service module into the different service layers, and defining the call relationships between the various business service modules based on the call relationships between the different service layers, to obtain microservice architecture template information matching the business system. The parameter configuration module is used to respond to the configuration operation of a third user and configure the running parameters associated with the business system for the code generation tool; wherein, the running parameters include at least the project type, package prefix, module name, table name, database address, username, password, and code storage directory of each business service module under the microservice architecture; the project type is divided into no module division, microservice division according to project module structure, microservice division according to business logic layer, and microservice division according to business logic layer and data access layer. The code generation module is used to synchronize the mapping relationship between the metadata and the class attributes to the Java memory of the microservice architecture by running a code generation tool, and to generate the backend code of the business system based on the mapping relationship and the microservice architecture template information. The application startup module is used to import the backend code into the programming IDE, and run the backend code through the IDE to start the microservice application of the business system.
6. An electronic device, characterized in that, The electronic device includes a processor and a memory storing computer program instructions; when the electronic device executes the computer program instructions, it implements the method as described in any one of claims 1-4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions that, when executed by a processor, implement the method as described in any one of claims 1-4.