[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN118747068A - Code generation method, device, equipment and medium based on micro-service architecture - Google Patents

Code generation method, device, equipment and medium based on micro-service architecture Download PDF

Info

Publication number
CN118747068A
CN118747068A CN202410884169.1A CN202410884169A CN118747068A CN 118747068 A CN118747068 A CN 118747068A CN 202410884169 A CN202410884169 A CN 202410884169A CN 118747068 A CN118747068 A CN 118747068A
Authority
CN
China
Prior art keywords
service
micro
code
business
configuration operation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410884169.1A
Other languages
Chinese (zh)
Inventor
程鑫
时望
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Qianjin Network Information Technology (shanghai) Co ltd
Original Assignee
Qianjin Network Information Technology (shanghai) Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Qianjin Network Information Technology (shanghai) Co ltd filed Critical Qianjin Network Information Technology (shanghai) Co ltd
Priority to CN202410884169.1A priority Critical patent/CN118747068A/en
Publication of CN118747068A publication Critical patent/CN118747068A/en
Pending legal-status Critical Current

Links

Landscapes

  • Stored Programmes (AREA)

Abstract

The application discloses a code generation method, device, equipment and medium based on a micro-service architecture. Comprising the following steps: based on a plurality of data tables configured for the service system, establishing a database of the service system; taking a table field in a data table as metadata, and creating a mapping relation between the metadata and class attributes in Java entity classes; defining each open source component referenced by the micro-service architecture and the calling relation among each service module in the service system to obtain micro-service architecture template information matched with the service system; synchronizing the mapping relation between the metadata and the class attributes into a Java memory of a micro-service architecture by running a code generation tool, and encoding based on the mapping relation and micro-service architecture template information to generate a back-end code of a service system; and importing the back-end code into the IDE, and starting the micro-service application of the service system by running the back-end code through the IDE. According to the embodiment of the application, the application development efficiency can be improved.

Description

Code generation method, device, equipment and medium based on micro-service architecture
Technical Field
The present application relates to the field of internet technologies, and in particular, to a method, an apparatus, a device, and a medium for generating a code based on a micro-service architecture.
Background
In the application development process, a developer needs to write codes to each functional module, but the manual writing of codes is troublesome and easy to make mistakes, repeated coding exists for different functional modules, in addition, different developers can form a set of own coding styles, the codes cannot conform to the unified coding specification, a great deal of time is consumed in the subsequent debugging and running processes, and the development efficiency of the application is affected.
Based on the above, how to reduce the repeated labor of developers and improve the application development efficiency in the application development scene is a technical problem to be solved currently.
Disclosure of Invention
In view of the above, the embodiments of the present application provide a method, an apparatus, a device, a medium, and a product for generating a code based on a micro-service architecture, which can reduce the repetitive labor of developers and improve the application development efficiency.
In a first aspect, an embodiment of the present application provides a method for generating a code based on a micro-service architecture, where the method includes: responding to a first user configuration operation, and establishing a database of a service system based on a plurality of data tables configured for the service system; taking a table field in a data table as metadata, and creating a mapping relation between the metadata and class attributes in Java entity classes; responding to a second user configuration operation, defining calling relations among all open source components referenced by the micro-service architecture and all service modules in the service system, and obtaining micro-service architecture template information matched with the service system; synchronizing the mapping relation between the metadata and the class attributes into a Java memory of a micro-service architecture by running a code generation tool, and encoding based on the mapping relation and micro-service architecture template information to generate a back-end code of a service system; and importing the back-end code into a programming tool IDE, and running the back-end code through the IDE to start micro-service application of the service system.
In some 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 respective open source components referenced by the micro service architecture, and calling relationships between respective business service modules in the business system, including: responding to a first configuration operation, screening a target open source component version number matched with a service system from all open source component version numbers displayed by a micro-service configuration platform, and obtaining all open source components referenced by a micro-service architecture; determining a dependency relationship between each open source component in response to the second configuration operation; and responding to the third configuration operation, and determining the calling relation among the business service modules.
In some implementations of the first aspect, the engineering structure of the micro service architecture is composed of a plurality of different service layers, where the plurality of different service layers at least includes a request access layer, a background application BFF layer, a service logic layer, a general service logic layer, and a data access layer, and determining, in response to a third configuration operation, a calling relationship between each service module includes: responding to a third configuration operation, dividing each business service module into different service layers; and defining the calling relation among the business service modules based on the calling relation among different service layers.
In some implementations of the first aspect, after responding to the second user configuration operation, further comprising: for each business service module, a synchronous call Java process and an asynchronous call Java process of the business service module are defined.
In some implementations of the first aspect, before running the code generation tool, the method further includes: configuring an operating parameter associated with the business system for the code generation tool in response to a third user configuration operation; the operation parameters at least comprise item types, package prefixes, module names, table names, database addresses, user names, passwords and code storage catalogues of all business service modules under the micro-service architecture, wherein the item types are divided into non-module division, micro-service division according to item module structures, micro-service division according to business logic layers, and micro-service division according to business logic layers and data access layers.
In some implementations of the first aspect, synchronizing, by running a code generation tool, a mapping relationship between metadata and class attributes into Java memory of a micro-service architecture includes: converting the code generating tool into an executable program by encapsulating the code of the code generating tool into an executable jar file; and calling a code generating tool by one-key operation executable program, reading metadata in a data table by using the code generating tool, and synchronizing the mapping relation between the metadata and the class attribute into a Java memory of the micro-service architecture.
In some implementations of the first aspect, the service system is a first service system, and after obtaining the micro service architecture template information matched with the service system, the method further includes: under the condition that the micro-service architecture template information matched with the first service system is obtained, responding to fourth user configuration operation, and modifying the micro-service architecture template information matched with the first service system to obtain micro-service architecture template information matched with the second service system; configuring an operating parameter associated with the second business system for the code generation tool in response to the fifth user configuration operation; and running a code generating tool based on the operation parameters associated with the second service system, synchronizing the mapping relation between the metadata and the class attribute in the database corresponding to the second service system into a Java memory of the micro service architecture, and coding based on the mapping relation in the database corresponding to the second service system and the micro service architecture template information of the second service system to generate a back-end code of the second service system.
In a second aspect, an embodiment of the present application provides a code generating apparatus based on a micro service architecture, the apparatus including: the database building module is used for responding to the first user configuration operation and building a database of the service system based on a plurality of data tables configured for the service system; the new module is used for taking a table field in the data table as metadata, and creating a mapping relation between the metadata and class attributes in Java entity classes; the template configuration module is used for responding to the second user configuration operation, defining each open source component referenced by the micro service architecture and the calling relation among each service module in the service system, and obtaining micro service architecture template information matched with the service system; the code generation module is used for synchronizing the mapping relation between the metadata and the class attribute into the Java memory of the micro-service architecture by running a code generation tool, and encoding based on the mapping relation and the micro-service architecture template information to generate a back-end code of the service system; and the application starting module is used for importing the back-end code into the programming tool IDE, and starting the micro-service application of the service system by running the back-end code through the IDE.
In some implementations of the second aspect, the second user configuration operation includes a first configuration operation, a second configuration operation, and a third configuration operation, and the template configuration module includes: the screening unit is used for responding to the first configuration operation, screening target open source component version numbers matched with the service system from all open source component version numbers displayed by the micro service configuration platform, and obtaining all open source components referenced by the micro service architecture; a determining unit configured to determine a dependency relationship between each of the open source components in response to the second configuration operation; and the determining unit is also used for determining the calling relation among the business service modules in response to the third configuration operation.
In some implementations of the second aspect, the engineering structure of the micro service architecture is composed of a plurality of different service layers, where the plurality of different service layers at least includes a request access layer, a background application BFF layer, a service logic layer, a general service logic layer, and a data access layer, and the determining unit is specifically configured to: responding to a third configuration operation, dividing each business service module into different service layers; and defining the calling relation among the business service modules based on the calling relation among different service layers.
In some implementations of the second aspect, the template configuration module is further configured to define, for each business service module, a synchronous invocation Java process and an asynchronous invocation Java process of the business service module after responding to the second user configuration operation.
In some implementations of the second aspect, the method further includes: a parameter configuration module for configuring an operating parameter associated with the business system for the code generation tool in response to a third user configuration operation prior to operating the code generation tool; the operation parameters at least comprise item types, package prefixes, module names, table names, database addresses, user names, passwords and code storage catalogues of all business service modules under the micro-service architecture, wherein the item types are divided into non-module division, micro-service division according to item module structures, micro-service division according to business logic layers, and micro-service division according to business logic layers and data access layers.
In some implementations of the second aspect, the code generation module is specifically configured to: converting the code generating tool into an executable program by encapsulating the code of the code generating tool into an executable jar file; and calling a code generating tool by one-key operation executable program, reading metadata in a data table by using the code generating tool, and synchronizing the mapping relation between the metadata and the class attribute into a Java memory of the micro-service architecture.
In some implementations of the second aspect, the service system is a first service system, and after obtaining the micro service architecture template information matched with the service system, the method further includes: the new adding module is used for responding to the fourth user configuration operation under the condition that the micro-service architecture template information matched with the first service system is obtained, and the micro-service architecture template information matched with the second service system is added by modifying the micro-service architecture template information matched with the first service system; a parameter configuration module for configuring operating parameters associated with the second business system for the code generation tool in response to a fifth user configuration operation; the code generation module is used for operating a code generation tool based on the operation parameters associated with the second service system, synchronizing the mapping relation between the metadata and the class attribute in the database corresponding to the second service system to the Java memory of the micro service architecture, and encoding based on the mapping relation in the database corresponding to the second service system and the micro service architecture template information of the second service system to generate a back-end code of the second service system.
In a third aspect, an embodiment of the present application provides an electronic device, including: a processor and a memory storing computer program instructions; the processor, when executing the computer program instructions, implements the steps of the micro-service architecture based code generation method as in the first aspect.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium having stored thereon computer program instructions which, when executed by a processor, implement the steps of the micro-service architecture based code generation method as in the first aspect.
In a fifth aspect, embodiments of the present application provide a computer program product stored in a non-volatile storage medium, which when executed by a processor implements the steps of the micro-service architecture based code generation method as in the first aspect.
In a sixth aspect, an embodiment of the present application provides a chip, where the chip includes a processor and a communication interface, where the communication interface is coupled to the processor, and where the processor is configured to execute a program or instructions to implement the steps of the micro-service architecture based code generation method as in the first aspect.
The application provides a code generation method, a device, equipment, a medium and a product based on a micro-service architecture, which take into account that under the specific development language and technical framework, the code structure of a large part of the code structures is the same except the data table structures of all modules in a service system, and based on the code structure, the code can be automatically generated by utilizing a micro-service technology in order to reduce the repeated code quantity. Specifically, through a first user configuration operation, a database matched with the service system and a mapping relation between metadata in a data table and class attributes in Java entity classes can be established, and through a second user configuration operation, calling relations among all open source components referred by a micro service architecture under the service system and all service modules in the service system can be defined, so that micro service architecture template information matched with the service system is obtained. On the basis, the mapping relation between the metadata and the class attribute in the service system can be synchronized into the Java memory of the micro-service architecture by running the code generation tool, and the code is encoded based on the mapping relation and the micro-service architecture template information to generate the back-end code of the service system. Therefore, the application can use Java as a development language, complete modeling of the database by using the micro-service technology, generate the appointed micro-service project code by using an automatic code generation tool, reduce repeated labor of developers, avoid low efficiency caused by manual code writing of the developers, quickly and effectively generate the micro-service application code, and improve the application development efficiency.
Drawings
In order to more clearly describe the technical solution of the embodiments of the present application, the following description briefly describes the drawings in the embodiments of the present application.
FIG. 1 is a flow chart of a method for generating code based on a micro-service architecture according to an embodiment of the present application;
FIG. 2 is a flow chart of a method for generating code based on a micro-service architecture according to another embodiment of the present application;
FIG. 3 is a schematic diagram of an engineering structure of a micro-service architecture according to an embodiment of the present application;
FIG. 4 is a flowchart illustrating a method for generating code based on a micro-service architecture according to still another embodiment of the present application;
FIG. 5 is a schematic diagram of a code generating device based on a micro-service architecture according to an embodiment of the present application;
fig. 6 is a schematic hardware structure of an electronic device according to an embodiment of the present application.
Detailed Description
The principles and spirit of the present application will be described below with reference to several exemplary embodiments. It will be appreciated that such embodiments are provided to make the principles and spirit of the application clear and thorough, and enabling those skilled in the art to better understand and practice the principles and spirit of the application. The exemplary embodiments provided herein are merely some, but not all embodiments of the application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the embodiments herein, are within the scope of the present application.
In this document, terms such as first, second, third, etc. are used solely to distinguish one entity (or action) from another entity (or action) without necessarily requiring or implying any order or relationship between such entities (or actions).
The code generation method based on the micro-service architecture provided by the embodiment of the application is described in detail below through specific embodiments and application scenes thereof with reference to the accompanying drawings.
Fig. 1 is a flow chart of a micro service architecture-based code generation method according to an embodiment of the present application, where an execution body of the micro service architecture-based code generation method may be a server, and the server may be connected to each service system, and the server is configured to generate corresponding back-end codes for each service system.
In an exemplary network recruitment scenario, each service system may include a B-end and a C-end corresponding to the network recruitment platform, where the B-end may include a network recruitment system, a network application recruitment system, a training system, and the like used by the recruiting user, and the C-end may include an due job seeking system, a network application job seeking system, a job recommendation system, and the like used by the job seeking user.
The micro-service architecture-based code generation method of the present application will be described below by taking an execution subject of the micro-service architecture-based code generation method as a server as an example. The execution body and the application scenario described above do not limit the present application.
As shown in fig. 1, the method for generating a code based on a micro service architecture according to an embodiment of the present application may include steps 110 to 150.
Step 110, responding to a first user configuration operation, and establishing a database of a service system based on a plurality of data tables configured for the service system;
step 120, using the table field in the data table as metadata, and creating a mapping relation between the metadata and class attributes in Java entity classes;
Step 130, responding to a second user configuration operation, defining calling relations among all open source components referenced by the micro service architecture and all business service modules in the business system, and obtaining micro service architecture template information matched with the business system;
Step 140, synchronizing the mapping relation between the metadata and the class attribute into the Java memory of the micro-service architecture by running a code generation tool, and encoding based on the mapping relation and the micro-service architecture template information to generate a back-end code of the service system;
Step 150, the back-end code is imported into the programming tool IDE, and the back-end code is run through the IDE to start the micro-service application of the service system.
According to the code generation method based on the micro-service architecture, provided by the embodiment of the application, under the condition that the data table structures of all modules in a service system are different under the specific development language and technical framework, a large part of code structures are identical, and based on the code structures, the code can be automatically generated by utilizing the micro-service technology in order to reduce the repeated code quantity. Specifically, through a first user configuration operation, a database matched with the service system and a mapping relation between metadata in a data table and class attributes in Java entity classes can be established, and through a second user configuration operation, calling relations among all open source components referred by a micro service architecture under the service system and all service modules in the service system can be defined, so that micro service architecture template information matched with the service system is obtained. On the basis, the mapping relation between the metadata and the class attribute in the service system can be synchronized into the Java memory of the micro-service architecture by running the code generation tool, and the code is encoded based on the mapping relation and the micro-service architecture template information to generate the back-end code of the service system. Therefore, the application can use Java as a development language, complete modeling of the database by using the micro-service technology, generate the appointed micro-service project code by using an automatic code generation tool, reduce repeated labor of developers, avoid low efficiency caused by manual code writing of the developers, quickly and effectively generate the micro-service application code, and improve the application development efficiency.
A specific implementation of the above steps is described in detail below in connection with specific embodiments.
Referring to step 110, in response to a first user configuration operation, a database of the business system is established based on a plurality of data tables configured for the business system.
In step 110, each service module may be included in the service system, where the service module is a functional module, for example, an identity authentication module, an order module, a commodity module, etc. in a mall system, and also, for example, a resume module, a job matching module, etc. in a recruitment system, which is not limited in this application. The back-end codes of the subsequent service systems are generated according to the database model, namely the mapping relation, and accord with the engineering sequence of modeling and then encoding of software engineering.
The first user configuration operation is used for newly establishing a corresponding data table for each business service module, so that the plurality of data tables comprise at least one data table corresponding to each business service module, and the data tables comprise table structure information such as field names, field types, whether filling is needed, default value information and the like of a plurality of table fields.
Illustratively, the first user configuration operation may be a code writing operation, for example, by entering the following code to build a data table:
the field name ' bigint (20) NOT NULL COMMENT ' primary key ',
The 'ctmid' bigint (20) NOT NULL COMMENT 'network is member Id',
The 'hruid' bigint (20) NOT NULL COMMENT 'network is the subscriber Id',
"Ep_name" varchar (300) NOT NULL DEFAULT "COMMENT" Enterprise titled',
'Ep_cert_no' varchar (50) NOT NULL DEFAULT "COMMENT 'unifies social credit code or business license registration number',
"Certify _status" v_varchar (50) NOT NULL DEFAULT "COMMENT" authentication status',
An 'auth_status' varchar (50) NOT NULL DEFAULT "COMMENT 'authorization status',
Step tinyint (4) NOT NULL DEFAULT '1' COMMENT ' authentication step: 1, initializing; 2, initializing data; 3, in authentication; 4, authentication failure (re-authenticatable); 5, authentication failure (non-reauthenticatable); 6, successful authentication; '
Step 120 is involved, in which table fields in the data table are used as metadata, and a mapping relationship between the metadata and class attributes in the Java entity class is created.
The first user configuration operation is also used to establish a mapping relationship between metadata and class attributes, in Java, class attributes (also known as member variables) are components of the class, are variables defined directly in the class, and are shared between all objects of the class, in step 120. Class attributes may be global, defined using a static key, indicating that the variable belongs to a class and not any particular instance of a class. Access to class attributes may be made through class names or object names, depending on the access modifier of the attribute (e.g., public, private, etc.). The class attribute corresponds to a table field in the data table, and the attribute value of the class attribute corresponds to a table field record in the data table, i.e., table structure information.
Step 130 is involved, in response to the second user configuration operation, defining calling relations between each open source component referenced by the micro service architecture and each service module in the service system, and obtaining micro service architecture template information matched with the service system.
In step 130, the second user configuration operation is used to select an open source component referenced by the micro service architecture from all open source components, and define a dependency relationship between each business service module, where the dependency relationship is a calling relationship.
In some embodiments of the present application, the second user configuration operation includes a first configuration operation, a second configuration operation, and a third configuration operation, and in response to the first configuration operation and the second configuration operation, each open source component referenced by the micro service architecture is defined, and in response to the third configuration operation, a calling relationship between each service module in the service system is defined.
In some embodiments of the present application, in order to avoid that the micro service application cannot operate normally due to the dependency conflict between the open source components, fig. 2 is a schematic flow diagram of a code generation method based on a micro service architecture according to another embodiment of the present application, where the second user configuration operation may include a first configuration operation, a second configuration operation, and a third configuration operation, and the defining, in the step 130, the open source components referred to by the micro service architecture and the calling relationships between the service modules in the service system may specifically include steps 210 to 230.
Step 210, in response to the first configuration operation, screening a target open source component version number matched with the service system from all open source component version numbers displayed by the micro service configuration platform to obtain each open source component referenced by the micro service architecture;
step 220, in response to the second configuration operation, determining a dependency relationship between each open source component;
In step 230, in response to the third configuration operation, a calling relationship between each business service module is determined.
Specifically, the micro service configuration platform may display version numbers of all open source components, and the first configuration operation may be a user operation for selecting a version number of a target open source component. The second configuration operation is used to build a dependency tree of version numbers of the respective target open source components, so that in response to the second configuration operation, dependencies between the respective open source components can be determined. The third configuration operation may be an operation of defining a call relationship between the respective business service modules through code writing or information filling.
In the embodiment of the application, all the open source components and the version numbers thereof which are cited by the micro service architecture under the service system can be determined by screening the version numbers of the target open source components, and the problem of incompatibility of the open source components caused by incompatibility of the version numbers can be avoided because the version numbers are determined, so that the normal operation of the subsequent micro service application is ensured. Moreover, the open source components needing to be integrated can be selected independently through the configuration file, the integrated and abundant open source components are high in selectivity, all the open source components and the business service modules are managed in a unified manner, the components are convenient to upgrade, the dependence between jar is prevented from conflicting, and the development efficiency can be improved.
In some embodiments of the present application, the engineering structure of the micro service architecture may be composed of a plurality of different service layers, where the plurality of different service layers at least includes a request access layer, a background application BFF layer, a service logic layer, a general service logic layer, and a data access layer, and the determining, in response to the third configuration operation, the call relationship between each service module in the step 230 may specifically include:
responding to a third configuration operation, dividing each business service module into different service layers;
And defining the calling relation among the business service modules based on the calling relation among different service layers.
Specifically, the micro service configuration platform may display a plurality of first input boxes associated with a plurality of different service layers, and the third configuration operation is a filling operation of filling corresponding service module identifiers in the plurality of first input boxes respectively; or the micro service configuration platform can display a plurality of second input boxes associated with each business service module, and the third configuration operation is a filling operation of filling corresponding service layer identifiers in the plurality of second input boxes respectively.
As an example, as shown in fig. 3, the engineering structure of the micro service architecture is respectively composed of a terminal display layer, an open interface, a request access layer (Web layer), a BFF layer (api-mics), a service logic layer (mics), a common service logic layer (common-mics) and a data access layer (dal-mics), wherein the common service logic layer can perform data transmission with an external interface or a third party platform, and the data access layer acquires data by querying a database DB.
In the embodiment of the application, the calling relation between different service layers can be defined through the engineering structure of the micro-service structure, so that the calling relation between different service modules can be accurately determined by limiting the association relation between the service modules and the service layers only by dividing each service module, and then the whole project structure based on the Spring Cloud micro-service structure can be generated by utilizing the calling relation without additionally modifying too many codes to run the micro-service application.
In some embodiments of the present application, after the step 130 responds to the second user configuration operation, the method may further include the following steps:
For each business service module, a synchronous call Java process and an asynchronous call Java process of the business service module are defined.
Step 140 is involved, by running a code generation tool, synchronizing the mapping relationship between metadata and class attributes to the Java memory of the micro-service architecture, and encoding based on the mapping relationship and the micro-service architecture template information to generate the back-end code of the service system.
In step 140, by running the code generation tool, the code generation tool may be enabled to encode based on the mapping relationship in the service system and the micro service architecture template information matched with the service system, to generate a back end code of the service system, where the back end code is a micro service code. The developer can set the code storage catalog corresponding to the service system, and after the back-end code of the service system is generated, the back-end code can be directly stored into the pre-configured code storage catalog in the form of a code file.
In some embodiments of the present application, before the code generation tool is executed in the step 140, the method may further include the following steps:
configuring an operating parameter associated with the business system for the code generation tool in response to a third user configuration operation;
The third user configuration operation may be code writing operation, and the operation parameters at least include a project type, a packet prefix, a module name, a table name, a database address, a user name, a password, a code storage directory of each service module under the micro-service architecture, and may further include a table prefix, a driver, a custom extension multiple cluster, springboot default mode, a DruidDataSource data source of the service module, etc., where the project type may be divided into a non-module division, a division of the micro-service according to a project module structure, a division of the micro-service according to a service logic layer, and a division of the micro-service according to a service logic layer and a data access layer.
Illustratively, the following is part of the code written when configuring the operating parameters by the third user configuration operation:
generating a code storage catalog, wherein the code storage catalog is not filled and defaults to a current catalog; selectable item
projectPath=XXX
Package prefix, default to com.jobs; the generated code complete package does not contain a module name; selectable item
packageNamePrefx=com.jobs.identity.auth
The module name, lowercase, support inter-word underline or cross bar segmentation; must fill in items
moduleName=identity-auth
Annotating the author name, # s; selectable item
author=dual
Table name # a plurality of comma-divided; must fill in items
tableNames=aut_str_mark
Prefix of the table is not included when the entity class files are generated after the prefix is declared; selectable item
tablePrefix=XXX
# Database Address, must fill in item
jdbcUrl=XXX
# Drive, must fill in items
jdbcDriverName=XXX
User name, # must fill in item
jdbcUserName=hrodbadmin
# Password, must fill in item
jdbcPassword=XXX
Whether or not the generated file is covered, # 0: is, 1: no, default value 0, optional
fileOverride=0
Mybatis framework type, 0:mybatis plus, 1:native mybatis,2:tk. Defaulting to: 0; selectable item
mybatisType=0
In the embodiment of the application, before the code generation tool is operated, the corresponding operation parameters can be configured for the code generation tool by utilizing the related information of the service system, so that the code generation tool is encoded based on the mapping relation in the service system and the micro-service architecture template information matched with the service system after operation, and the back-end code matched with the service system is smoothly generated. And each business service module can be matched with different project types according to actual requirements, so that the suitability of the subsequently generated back-end codes is improved.
In some embodiments of the present application, the step 140 of synchronizing the mapping relationship between the metadata and the class attribute into the Java memory of the micro-service architecture by running the code generation tool may include the following steps:
Converting the code generating tool into an executable program by encapsulating the code of the code generating tool into an executable jar file;
And calling a code generating tool by one-key operation executable program, reading metadata in a data table by using the code generating tool, and synchronizing the mapping relation between the metadata and the class attribute into a Java memory of the micro-service architecture.
Specifically, an executable JAR file is a self-contained Java application that is stored in a specially configured JAR file and can be executed directly by a Java virtual machine (Java Virtual Machine, JVM) without prior extraction of the file or setting of class paths. The executable JAR facilitates publishing and executing Java applications.
In the embodiment of the application, the original code generation tool is in the form of a command line, and is packaged into jar to be converted into the executable program running by one key, so that the integration degree of the executable program is improved without extracting files or setting class paths in advance, and a developer can operate by one key to generate codes, the operation is simple, and the generation efficiency of the back-end codes is improved.
In some embodiments of the present application, the service system may be used as a first service system, and in order to further improve the application development efficiency, fig. 4 is a schematic flow chart of a code generation method based on a micro service architecture according to still another embodiment of the present application, after the micro service architecture template information matched with the service system is obtained in the step 140, the method may further include steps 410 to 430.
Step 410, in case of obtaining the micro service architecture template information matched with the first service system, responding to the fourth user configuration operation, and newly adding the micro service architecture template information matched with the second service system by modifying the micro service architecture template information matched with the first service system;
Step 420, in response to the fifth user configuration operation, configuring an operating parameter associated with the second business system for the code generation tool;
step 430, running a code generation tool based on the operation parameters associated with the second service system, synchronizing the mapping relation between the metadata and the class attribute in the database corresponding to the second service system to the Java memory of the micro service architecture, and encoding based on the mapping relation in the database corresponding to the second service system and the micro service architecture template information of the second service system to generate the back end code of the second service system.
Specifically, the micro service architecture template information matched with the first service system may be first micro service architecture template information, the micro service architecture template information matched with the second service system may be second micro service architecture template information, the fourth user configuration operation is used for adjusting on the basis of the first micro service architecture template information, specifically, may be to adjust an open source component referenced by the micro service architecture, and adjust a call relationship between each service module in the first service system to a call relationship between each service module in the second service system, so as to obtain second micro service architecture template information matched with the second service system.
In some embodiments of the present application, before the step 430, a database of the second service system may be pre-established, where the database includes a data table corresponding to each service module in the second service system, and a mapping relationship between metadata and class attributes in Java entity class is created by using a table field in the data table as metadata, so as to obtain a mapping relationship in the database corresponding to the second service system.
In the embodiment of the application, after the first configuration generates the micro-service architecture template information, the micro-service architecture with suitability to each service system can be respectively created on the basis of the characteristics of different service systems to obtain the corresponding micro-service architecture template information matched with the service system. Therefore, the micro service architecture template information matched with other systems can be obtained by proper adjustment on the basis of the micro service architecture template information of the first service system, and then the back end codes of the service systems are correspondingly created by utilizing the micro service architecture template information, so that the operation can be performed without additionally modifying too many codes, the code adjustment amount is small, and the micro service application development efficiency of the service systems can be further improved.
In some embodiments of the present application, after the first micro service architecture template information matched with the first service system is obtained in step 130, the first micro service architecture template information may be stored in a template library, so that the first micro service architecture template information may be obtained from the template library in step 410.
And the micro-service architecture template information of each subsequent service system can be uploaded to a template library for storage, so that the micro-service architecture template information is convenient to call and use when micro-service applications of other service systems are developed subsequently.
Step 150 is involved, the back-end code is imported into the programming tool IDE, and the back-end code is run through the IDE to launch the micro-service application of the business system.
In step 150, a writer tool (INTEGRATED DEVELOPMENT ENVIRONMENT, IDE) is a tool for software development that provides code editing, compiling, debugging, and deployment functions. The IDE can convert the back-end code into executable programs or interpretations for execution, and can support back-end development and mobile application development. Here, the executable program is a micro-service application.
In some embodiments of the present application, the micro-service architecture is based on a Spring Boot framework, and the underlying framework of the code generation tool is mybatis-plus-generator.
In some embodiments of the application, the code generation tool may be AutoGenerator, code-gen, code Generate ORM.
It should be noted that, in the code generation method based on the micro-service architecture provided by the embodiment of the present application, the implementation language of the micro-service may be programming languages such as c#, go, typescript, python, and the like, which is not limited in particular.
Correspondingly to the method embodiment of the application, the application further provides a code generation device based on the micro-service architecture.
Fig. 5 is a schematic structural diagram of a code generating device based on a micro service architecture according to an embodiment of the present application. As shown in fig. 5, the micro service architecture-based code generation apparatus 500 may include: a library building module 510, a new building module 520, a template configuration module 530 and a code generation module 540.
The database building module 510 is configured to respond to the first user configuration operation, and build a database of the service system based on a plurality of data tables configured for the service system; a new module 520, configured to use a table field 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 530 is configured to respond to a second user configuration operation, define calling relations between each open source component referenced by the micro service architecture and each service module in the service system, and obtain micro service architecture template information matched with the service system; the code generating module 540 is configured to synchronize the mapping relationship between the metadata and the class attribute to the Java memory of the micro service architecture by running a code generating tool, and encode the mapping relationship and the micro service architecture template information to generate a back end code of the service system; and the application starting module is used for importing the back-end code into the programming tool IDE, and starting the micro-service application of the service system by running the back-end code through the IDE.
The code generating device based on the micro-service architecture provided by the embodiment of the application considers that under the specific development language and technical framework, the code structures of a large part of the code structures are identical except for the data table structures of all modules in the service system, and based on the code structures, the code can be automatically generated by utilizing the micro-service technology in order to reduce the repeated code quantity. Specifically, through a first user configuration operation, a database matched with the service system and a mapping relation between metadata in a data table and class attributes in Java entity classes can be established, and through a second user configuration operation, calling relations among all open source components referred by a micro service architecture under the service system and all service modules in the service system can be defined, so that micro service architecture template information matched with the service system is obtained. On the basis, the mapping relation between the metadata and the class attribute in the service system can be synchronized into the Java memory of the micro-service architecture by running the code generation tool, and the code is encoded based on the mapping relation and the micro-service architecture template information to generate the back-end code of the service system. Therefore, the application can use Java as a development language, complete modeling of the database by using the micro-service technology, generate the appointed micro-service project code by using an automatic code generation tool, reduce repeated labor of developers, avoid low efficiency caused by manual code writing of the developers, quickly and effectively generate the micro-service application code, and improve the application development efficiency.
In some embodiments of the present application, the second user configuration operation includes a first configuration operation, a second configuration operation, and a third configuration operation, and the template configuration module 530 includes: the screening unit is used for responding to the first configuration operation, screening target open source component version numbers matched with the service system from all open source component version numbers displayed by the micro service configuration platform, and obtaining all open source components referenced by the micro service architecture; a determining unit configured to determine a dependency relationship between each of the open source components in response to the second configuration operation; and the determining unit is also used for determining the calling relation among the business service modules in response to the third configuration operation.
In some embodiments of the present application, the engineering structure of the micro service architecture is composed of a plurality of different service layers, where the plurality of different service layers at least includes a request access layer, a background application BFF layer, a service logic layer, a general service logic layer, and a data access layer, and the determining unit is specifically configured to: responding to a third configuration operation, dividing each business service module into different service layers; and defining the calling relation among the business service modules based on the calling relation among different service layers.
In some embodiments of the present application, the template configuration module 530 is further configured to define, for each business service module, a synchronous call Java process and an asynchronous call Java process of the business service module after responding to the second user configuration operation.
In some embodiments of the application, further comprising: a parameter configuration module for configuring an operating parameter associated with the business system for the code generation tool in response to a third user configuration operation prior to operating the code generation tool; the operation parameters at least comprise item types, package prefixes, module names, table names, database addresses, user names, passwords and code storage catalogues of all business service modules under the micro-service architecture, wherein the item types are divided into non-module division, micro-service division according to item module structures, micro-service division according to business logic layers, and micro-service division according to business logic layers and data access layers.
In some embodiments of the present application, the code generation module 540 is specifically configured to: converting the code generating tool into an executable program by encapsulating the code of the code generating tool into an executable jar file; and calling a code generating tool by one-key operation executable program, reading metadata in a data table by using the code generating tool, and synchronizing the mapping relation between the metadata and the class attribute into a Java memory of the micro-service architecture.
In some embodiments of the present application, the service system is a first service system, and after obtaining the micro service architecture template information matched with the service system, the method further includes: the new adding module is used for responding to the fourth user configuration operation under the condition that the micro-service architecture template information matched with the first service system is obtained, and the micro-service architecture template information matched with the second service system is added by modifying the micro-service architecture template information matched with the first service system; a parameter configuration module for configuring operating parameters associated with the second business system for the code generation tool in response to a fifth user configuration operation; the code generation module is used for operating a code generation tool based on the operation parameters associated with the second service system, synchronizing the mapping relation between the metadata and the class attribute in the database corresponding to the second service system to the Java memory of the micro service architecture, and encoding based on the mapping relation in the database corresponding to the second service system and the micro service architecture template information of the second service system to generate a back-end code of the second service system.
The code generating device based on the micro-service architecture provided by the embodiment of the application can realize each process realized by the service platform in the method embodiment of fig. 1-4 and can realize the same technical effect, and is not repeated here for avoiding repetition.
Fig. 6 is a schematic hardware structure of an electronic device according to an embodiment of the present application.
As shown in fig. 6, the electronic device 600 includes a memory 601, a processor 602, and a computer program stored on the memory 601 and executable on the processor 602.
In one example, the processor 602 may include a Central Processing Unit (CPU), or an Application SPECIFIC INTEGRATED Circuit (ASIC), or may be configured as one or more integrated circuits that implement embodiments of the present application.
The Memory 601 may include Read-Only Memory (ROM), random-access Memory (Random Access Memory, RAM), magnetic disk storage media devices, optical storage media devices, flash Memory devices, electrical, optical, or other physical/tangible Memory storage devices. Thus, in general, the memory comprises one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software comprising 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 method of opening a card in an embodiment according to the first aspect of the application.
The processor 602 executes a computer program corresponding to the executable program code by reading the executable program code stored in the memory 601 for realizing the card opening method in the embodiment of the first aspect described above.
In some examples, electronic device 600 may also include a communication interface 603 and a bus 610. As shown in fig. 6, the memory 601, the processor 602, and the communication interface 603 are connected to each other through a bus 610 and perform communication with each other.
The communication interface 603 is mainly used for implementing communication between each module, apparatus, unit and/or device in the embodiment of the present application. Input devices and/or output devices may also be accessed through the communication interface 603.
Bus 610 includes hardware, software, or both, coupling the components of electronic device 600 to one another. By way of example, and not limitation, bus 610 may include an accelerated graphics Port (ACCELERATED GRAPHICS Port, AGP) or other graphics Bus, an enhanced industry Standard architecture (Enhanced Industry Standard Architecture, EISA) Bus, a Front Side Bus (FSB), a HyperTransport (HT) interconnect, an industry Standard architecture (Industry Standard Architecture, ISA) Bus, an Infiniband interconnect, a Low Pin Count (LPC) Bus, a memory Bus, a micro channel architecture (Micro Channel Architecture, MCA) Bus, a peripheral component interconnect (PERIPHERAL COMPONENT INTERCONNECT, PCI) Bus, a PCI-Express (PCI-E) Bus, a serial advanced technology attachment (SERIAL ADVANCED Technology Attachment, SATA) Bus, a video electronics standards Association local (Video Electronics Standards Association Local Bus, VLB) Bus, or other suitable Bus, or a combination of two or more of the above. Bus 610 may include one or more buses, where appropriate. Although embodiments of the application have been described and illustrated with respect to a particular bus, the application contemplates any suitable bus or interconnect.
The electronic device provided by the embodiment of the application can realize each process realized by the electronic device in the method embodiment of fig. 1-4, and can realize the same technical effects, and in order to avoid repetition, the description is omitted here.
In combination with the method for generating the code based on the micro-service architecture in the above embodiment, the embodiment of the application can be implemented by providing a computer storage medium. The computer storage medium has stored thereon computer program instructions; the computer program instructions, when executed by a processor, implement the steps of any of the micro-service architecture based code generation methods of the above embodiments.
In combination with the micro-service architecture-based code generation method in the above embodiment, an embodiment of the present application may be implemented by providing a computer program product. The (computer) program product is stored in a non-volatile storage medium, which program product, when being executed by at least one processor, implements the steps of the micro-service architecture based code generation method of any of the above embodiments.
The embodiment of the application further provides a chip, the chip comprises a processor and a communication interface, the communication interface is coupled with the processor, the processor is used for running programs or instructions, the processes of the code generation method embodiment based on the micro-service architecture can be realized, the same technical effects can be achieved, and the repetition is avoided, and the description is omitted here.
It should be understood that the chips referred to in the embodiments of the present application may also be referred to as system-on-chip chips, chip systems, or system-on-chip chips, etc.
It should be understood that the application is not limited to the particular arrangements and instrumentality described above and shown in the drawings. For the sake of brevity, a detailed description of known methods is omitted here. In the above embodiments, several specific steps are described and shown as examples. The method processes of the present application are not limited to the specific steps described and shown, but various changes, modifications and additions, or the order between steps may be made by those skilled in the art after appreciating the spirit of the present application.
The functional blocks shown in the above-described structural block diagrams may be implemented in hardware, software, firmware, or a combination thereof. When implemented in hardware, it may be, for example, an electronic Circuit, application SPECIFIC INTEGRATED Circuit (ASIC), appropriate firmware, plug-in, function card, or the like. When implemented in software, the elements of the application are the programs or code segments used to perform the required tasks. The program or code segments may be stored in a machine readable medium or transmitted over transmission media or communication links by a data signal carried in a carrier wave. A "machine-readable medium" may include any medium that can store or transfer information. Examples of machine-readable media include electronic circuitry, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio Frequency (RF) links, and the like. The code segments may be downloaded via computer networks such as the internet, intranets, etc.
It should also be noted that the exemplary embodiments mentioned in this disclosure describe some methods or systems based on a series of steps or devices. The present application is not limited to the order of the above-described steps, that is, the steps may be performed in the order mentioned in the embodiments, or may be performed in a different order from the order in the embodiments, or several steps may be performed simultaneously.
Aspects of the present disclosure are described above with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the disclosure. It will be understood that each block of 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 may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions/acts specified in the flowchart and/or block diagram block or blocks. Such a processor may be, but is not limited to being, a general purpose processor, a special purpose processor, an application specific processor, or a field programmable logic circuit. It will also be understood that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware which performs the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In the foregoing, only the specific embodiments of the present application are described, and it will be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the systems, modules and units described above may refer to the corresponding processes in the foregoing method embodiments, which are not repeated herein. It should be understood that the scope of the present application is not limited thereto, and any equivalent modifications or substitutions can be easily made by those skilled in the art within the technical scope of the present application, and they should be included in the scope of the present application.

Claims (10)

1. A method for generating code based on a micro-service architecture, comprising:
responding to a first user configuration operation, and establishing a database of a business system based on a plurality of data tables configured for the business system;
Taking a table field in the data table as metadata, and creating a mapping relation between the metadata and class attributes in Java entity classes;
Responding to a second user configuration operation, defining each open source component referenced by a micro service architecture and calling relations among each service module in the service system, and obtaining micro service architecture template information matched with the service system;
synchronizing the mapping relation between the metadata and the class attributes into a Java memory of the micro service architecture by running a code generation tool, and encoding based on the mapping relation and the micro service architecture template information to generate a back-end code of the service system;
and importing the back-end code into an IDE (programming tool), and running the back-end code through the IDE to start micro-service application of the service system.
2. The method of claim 1, wherein the second user configuration operation comprises a first configuration operation, a second configuration operation, and a third configuration operation, wherein defining the calling relationship between each open source component referenced by the micro-service architecture and each business service module in the business system comprises:
responding to the first configuration operation, screening target open source component version numbers matched with the service system from all open source component version numbers displayed by a micro service configuration platform, and obtaining all open source components referenced by the micro service architecture;
determining a dependency relationship between the respective open source components in response to the second configuration operation;
And responding to the third configuration operation, and determining the calling relation among the business service modules.
3. The method of claim 2, wherein the engineering structure of the micro-service architecture is composed of a plurality of different service layers, the plurality of different service layers including at least a request access layer, a background application BFF layer, a business logic layer, a generic business logic layer, and a data access layer, and wherein the determining, in response to the third configuration operation, a call relationship between the respective business service modules includes:
Responsive to the third configuration operation, partitioning the respective business service modules to the different service layers;
And defining the calling relation among the business service modules based on the calling relation among different service layers.
4. The method of claim 1, further comprising, after said responding to the second user configuration operation:
for each business service module, a synchronous call Java process and an asynchronous call Java process of the business service module are defined.
5. The method of claim 1, further comprising, prior to the running the code generation tool:
configuring an operating parameter associated with the business system for the code generation tool in response to a third user configuration operation;
The operation parameters at least comprise item types, package prefixes, module names, table names, database addresses, user names, passwords and code storage catalogues of all business service modules under the micro-service architecture, wherein the item types are divided into non-module division, micro-service division according to item module structures, micro-service division according to business logic layers and data access layers.
6. The method of claim 1, wherein synchronizing, by running a code generation tool, the mapping relationship between the metadata and the class attributes into Java memory of the micro-service architecture comprises:
converting the code generating tool into an executable program by packaging the code of the code generating tool into an executable jar file;
And operating the executable program through one key, calling the code generating tool, and reading metadata in the data table by utilizing the code generating tool, and synchronizing the mapping relation between the metadata and the class attribute into the Java memory of the micro-service architecture.
7. The method of claim 1, wherein the business system is a first business system, and after the obtaining the micro-service architecture template information matched with the business system, further comprising:
under the condition that the micro-service architecture template information matched with the first service system is obtained, responding to fourth user configuration operation, and newly adding the micro-service architecture template information matched with the second service system by modifying the micro-service architecture template information matched with the first service system;
configuring, for the code generation tool, operating parameters associated with the second business system in response to a fifth user configuration operation;
And operating the code generation tool based on the operation parameters associated with the second service system, synchronizing the mapping relation between the metadata and the class attributes in the corresponding database of the second service system to the Java memory of the micro service architecture, and encoding based on the mapping relation in the corresponding database of the second service system and the micro service architecture template information of the second service system to generate a back-end code of the second service system.
8. A micro-service architecture-based code generation apparatus, comprising:
The database building module is used for responding to the first user configuration operation and building a database of the service system based on a plurality of data tables configured for the service system;
The new building module is used for taking a table field in the data table as metadata and building a mapping relation between the metadata and class attributes in Java entity classes;
The template configuration module is used for responding to a second user configuration operation, defining each open source component referenced by the micro service architecture and the calling relation among each business service module in the business system, and obtaining micro service architecture template information matched with the business system;
the code generation module is used for synchronizing the mapping relation between the metadata and the class attribute into the Java memory of the micro service architecture by running a code generation tool, and encoding based on the mapping relation and the micro service architecture template information to generate a back-end code of the service system;
and the application starting module is used for importing the back-end code into a programming tool IDE, and starting the micro-service application of the service system by running the back-end code through the IDE.
9. An electronic device, the electronic device comprising: a processor and a memory storing computer program instructions; the electronic device, when executing the computer program instructions, implements the method of any of claims 1-7.
10. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon computer program instructions which, when executed by a processor, implement the method according to any of claims 1-7.
CN202410884169.1A 2024-07-03 2024-07-03 Code generation method, device, equipment and medium based on micro-service architecture Pending CN118747068A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410884169.1A CN118747068A (en) 2024-07-03 2024-07-03 Code generation method, device, equipment and medium based on micro-service architecture

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410884169.1A CN118747068A (en) 2024-07-03 2024-07-03 Code generation method, device, equipment and medium based on micro-service architecture

Publications (1)

Publication Number Publication Date
CN118747068A true CN118747068A (en) 2024-10-08

Family

ID=92921135

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410884169.1A Pending CN118747068A (en) 2024-07-03 2024-07-03 Code generation method, device, equipment and medium based on micro-service architecture

Country Status (1)

Country Link
CN (1) CN118747068A (en)

Similar Documents

Publication Publication Date Title
CN109840429B (en) Intelligent contract deployment and calling method and device
CN111797073B (en) Database management method, electronic device, and computer-readable storage medium
CN107506181A (en) Business processing, data processing method, device and electronic equipment
CN110806945B (en) Interface docking method, device and computer readable medium
CN111611441B (en) Heterogeneous data processing method and device and computer equipment
CN110895471A (en) Installation package generation method, device, medium and electronic equipment
CN111475192B (en) Method, device, storage medium and system for performing thermal augmentation on game server
CN111414391A (en) Method and system for accessing multiple data sources
CN112286643B (en) Transaction processing method, device, equipment and medium for Ether house virtual machine
CN113672204A (en) Interface document generation method, system, electronic equipment and storage medium
CN112286641B (en) Transaction processing method, device, equipment and medium for Ether house virtual machine
US10579366B2 (en) Data upgrade framework for distributed systems
CN112199079B (en) System docking method, computing device and storage medium
CN111078319B (en) Configuration data management method, device, storage medium and computer readable medium
CN111562907A (en) Conversion method and system of user-defined interface data
US10579342B1 (en) Encapsulated application templates for containerized application software development
CN109388406A (en) Convert method and device, the storage medium, electronic device of java code
CN116521181B (en) Script data processing method, device, equipment and medium based on game system
CN118747068A (en) Code generation method, device, equipment and medium based on micro-service architecture
CN108595160B (en) Method and storage medium for calling native object by JS
CN114449063A (en) Message processing method, device and equipment
CN114064176A (en) View interaction method and device, electronic equipment and computer readable medium
CN111581578A (en) Interface request processing method and device
CN113986207B (en) Software architecture generating and calling method and device
CN111414162B (en) Data processing method, device and equipment thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination