A code generation method, device, intelligent terminal and storage medium
By obtaining business information and determining code configuration information and templates based on it, code that meets the requirements is generated, which solves the problems of cumbersome code generation steps and low efficiency in the existing technology, and realizes efficient code that is compatible with multiple databases under the microservice architecture. generate.
Patent Information
- Application Number
- CN202011625893.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-30
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2040-12-30
AI Technical Summary
The code generation steps in the prior art are cumbersome, inefficient, and cannot be compatible with multiple databases under the advanced microservice architecture development model.
By obtaining the business information, the code configuration information corresponding to the business type is determined according to the corresponding relationship between the pre-stored business information and the code configuration information. Then, according to the correspondence between the code configuration information and the code template, the corresponding code template is determined. Finally, code is generated based on the code template and business information.
It simplifies the traditional code generation process, improves code generation efficiency, and is compatible with multiple databases under the microservice architecture.
Smart Images

Figure CN112631568B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of code generation, and in particular to a code generation method, device, intelligent terminal and storage medium. Background Art
[0002] Existing JAVA automatic code generation tools can only generate a small amount of simple code, and the technology is outdated. The supported database type is usually only MYSQL. There is a lack of systems that can automatically generate code for multiple databases under the advanced microservice architecture development model. In addition, the existing code generation technology has cumbersome steps and low code generation efficiency.
[0003] Therefore, the prior art still needs to be improved and enhanced. Summary of the invention
[0004] The present invention provides a code generation method, device, intelligent terminal and storage medium, aiming to solve the problems of complicated steps and low code generation efficiency in the prior art code generation technology.
[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is as follows:
[0006] In a first aspect, the present invention provides a code generation method, wherein the method comprises:
[0007] Acquire service information, and determine the code configuration information corresponding to the service type according to the pre-stored correspondence between the service information and the code configuration information;
[0008] Determining a code template corresponding to the code configuration information according to a pre-stored correspondence between the code configuration information and the code template;
[0009] Generate code according to the code template and the business information.
[0010] In one implementation, the acquiring of the service information, and determining the code configuration information corresponding to the service type according to a pre-stored correspondence between the service information and the code configuration information, includes:
[0011] Get business information entered by the user;
[0012] Determining the service type corresponding to the service information according to the pre-stored correspondence between the service information and the service type;
[0013] The code configuration information corresponding to the service type is determined according to the pre-stored correspondence between the service type and the code configuration information.
[0014] In one implementation, determining the code configuration information corresponding to the service type according to the pre-stored correspondence between the service type and the code configuration information includes:
[0015] Matching the service type with a preset code database, wherein the code database pre-stores a correspondence between the service type and the code configuration information;
[0016] Determine the code configuration information corresponding to the business type, wherein the code configuration information includes code type information and service component information.
[0017] In one implementation, the code type information includes any one of a tool class, an entity class, a data access class, a service class, an interface class, and an implementation layer class.
[0018] In one implementation, the service component information includes any one of a gateway component, a registration center component, a configuration center component, and a scheduling task center component.
[0019] In one implementation, determining the code template corresponding to the code configuration information according to the pre-stored correspondence between the code configuration information and the code template includes:
[0020] Obtaining a preset code engine rule library, wherein the code engine rule library pre-stores a correspondence between the code configuration information and the code template;
[0021] According to the code configuration information and the code engine rule base, a code template corresponding to the code configuration information is determined.
[0022] In one implementation, the generating the code according to the code template and the business information includes:
[0023] Parsing the code template to obtain a parsed code template;
[0024] The business information is input into the parsed code template to generate code.
[0025] In a second aspect, an embodiment of the present invention provides a code generation device, wherein the device includes:
[0026] An information acquisition module, used to acquire service information, and determine the code configuration information corresponding to the service type according to the pre-stored correspondence between the service information and the code configuration information;
[0027] A template generation module, used to determine a code template corresponding to the code configuration information according to a pre-stored correspondence between the code configuration information and the code template;
[0028] The code generation module is used to generate code according to the code template and the business information.
[0029] In a third aspect, an embodiment of the present invention further provides an intelligent device, comprising a memory, a processor, and a code generation program stored in the memory and executable on the processor, wherein when the processor executes the code generation program, the steps of the code generation method described in any one of the above-mentioned schemes are implemented.
[0030] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium on which a code generation program is stored. When the code generation program is executed by a processor, the steps of the code generation method described in any one of the above schemes are implemented.
[0031] Beneficial effect: Compared with the prior art, the present invention provides a code generation method. The present invention first obtains business information, and determines the code configuration information corresponding to the business type according to the pre-stored correspondence between the business information and the code configuration information. Then, according to the pre-stored correspondence between the code configuration information and the code template, the code template corresponding to the code configuration information is determined. Finally, the code is generated according to the code template and the business information. It can be seen that the present invention can obtain the code configuration information corresponding to the business information, and can generate a code template corresponding to the code configuration information. According to the code template, the code that meets the requirements can be generated, which simplifies the traditional code generation process and improves the code generation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A flowchart of a specific implementation method of code generation provided by an embodiment of the present invention.
[0033] Figure 2 A flowchart of obtaining code configuration information during code generation provided by an embodiment of the present invention.
[0034] Figure 3 A flowchart of generating a code template in code generation provided in an embodiment of the present invention.
[0035] Figure 4 A flowchart of generating code in the code generation provided in an embodiment of the present invention.
[0036] Figure 5 It is a principle block diagram of a code generation device provided by an embodiment of the present invention.
[0037] Figure 6 It is a block diagram of the internal structure principle of the smart device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0039] Existing JAVA automatic code generation tools can only generate a small amount of simple code, and the technology is outdated. The supported database type is usually only MYSQL. There is a lack of systems that can automatically generate code in an advanced microservice architecture development mode and compatible with multiple databases. In addition, the steps of existing code generation technology are cumbersome and the code generation efficiency is low. For example, the following steps are required when generating code in the existing technology: first, create a database table in the database; then manually write an entity class; then manually write a data access class; then manually write a service class; then manually write an interface class; then manually write an implementation layer class; and finally manually write business logic. It can be seen that the steps of generating code in the existing technology are cumbersome and inefficient.
[0040] In order to solve the problems of the prior art, the present invention provides a code generation method. When implemented specifically, the present embodiment first obtains business information, and determines the code configuration information corresponding to the business type according to the pre-stored correspondence between the business information and the code configuration information. Then, according to the pre-stored correspondence between the code configuration information and the code template, the code template corresponding to the code configuration information is determined. Finally, the code is generated according to the code template and the business information. It can be seen that the present embodiment can obtain the code configuration information corresponding to the business information, and can generate a code template corresponding to the code configuration information. According to the code template, the code that meets the requirements can be generated, which simplifies the traditional code generation process and improves the code generation efficiency.
[0041] Exemplary Methods
[0042] The code generation method of this embodiment can be applied to a smart terminal, which can be a computer, a mobile phone or other smart terminal products. Figure 1 As shown in , the code generation method includes the following steps:
[0043] Step S100: Acquire service information, and determine code configuration information corresponding to the service type according to the pre-stored correspondence between the service information and code configuration information.
[0044] When generating a code, the user needs to input the business information, and the smart terminal generates the code by inputting the business information. Therefore, before generating the code, the smart terminal first obtains the business information, and the business information is used to reflect the type of code that the user wants to generate. Therefore, the smart terminal can obtain the code configuration information corresponding to the business information without relying on the correspondence between the pre-stored business information and the code configuration information. The code configuration information is the information required in the code generation process and is the key to code generation. In addition, the business information in this embodiment reflects the type of code that the user wants to generate, and the code configuration information corresponds to the business information, so the code configuration information reflects the type of code generation.
[0045] In one implementation, Figure 2 As shown in , the step S100 specifically includes the following steps:
[0046] Step S101, obtaining business information input by the user;
[0047] Step S102: determining the service type corresponding to the service information according to the pre-stored correspondence between the service information and the service type;
[0048] Step S103: Determine the code configuration information corresponding to the service type according to the pre-stored correspondence between the service type and the code configuration information.
[0049] During specific implementation, this embodiment first obtains the business information input by the user. Since the business information can reflect the type of code that the user wants to generate, this embodiment can determine the business type corresponding to the business information based on the pre-stored correspondence between the business information and the business type. The business type is used to determine the code configuration information. In this embodiment, there are many ways to obtain the business type from the business information. For example, the business information can be parsed to obtain the type identifier in the business information, and then the corresponding business type can be determined based on the type identifier. In this embodiment, the correspondence between the type identifier and the business type is pre-set and stored. Therefore, after obtaining the type identifier in the business information, this embodiment can quickly determine the business type based on the type identifier, so as to determine the code configuration information corresponding to the business type based on the business type.
[0050] Specifically, in this embodiment, when generating code configuration information, the business type is first matched with a preset code database. In this embodiment, the code database is pre-set, and the correspondence between the business type and the code configuration information is pre-stored in the code database, and the code database can be set with multiple types, including MYSQL, Oracle, DB2, PostgreSQL, SQLServer, MongDB and the connection address of the corresponding database. The code type information is used to correspond to the business type, reflecting the type of code that the user wants to generate. In this embodiment, after determining the business type, the code configuration information corresponding to the business type can be determined according to the correspondence between the business type and the code configuration information. The code configuration information includes code type information and service component information. The code database pre-stores multiple code type information and service component information. The code type information includes any one of a tool class, an entity class, a data access class, a service class, an interface class, and an implementation layer class. The service component information includes any one of a gateway component (such as optional gateway or zuul), a registration center component (such as optional nacos or eureka), a configuration center component (such as nacos) and a scheduling task center component.
[0051] Step S200: Determine a code template corresponding to the code configuration information according to a pre-stored correspondence between the code configuration information and the code template.
[0052] Since the code configuration information includes the code type information and service component information corresponding to the business type, after obtaining the code configuration information, this embodiment can obtain the corresponding code template based on the correspondence between the pre-stored code configuration information and the code template. The code template obtained in this embodiment is used to generate code in subsequent steps, and through the code template, code that meets the requirements can be generated more quickly.
[0053] In one implementation, Figure 3 As shown in , the step S200 specifically includes:
[0054] Step S201: obtaining a preset code engine rule library, wherein the code engine rule library pre-stores a correspondence between the code configuration information and the code template;
[0055] Step S202: Determine a code template corresponding to the code configuration information according to the code configuration information and the code engine rule base.
[0056] During specific implementation, this embodiment first obtains a preset code engine rule base, and the code engine rule base is used to generate code templates. The code engine rule base pre-stores the correspondence between the code configuration information and the code template. And the code engine rule base stores the generation rules of code templates corresponding to various code types. Therefore, after obtaining the code configuration information, this embodiment can obtain the code type information from the code configuration information, and then find the code generation rule corresponding to the code type information in the code engine rule base based on the code type information, so that the corresponding code template can be generated according to the code generation rule.
[0057] Step S300: Generate code according to the code template and the business information.
[0058] After the code template is obtained, the present embodiment can generate the code required by the corresponding user according to the code template. In specific implementation, when the code is generated, the present embodiment generates the code based on the business information and the code template.
[0059] In one implementation, Figure 4 As shown in , step S300 specifically includes:
[0060] Step S301, parsing the code template to obtain a parsed code template;
[0061] Step S302: input the business information into the parsed code template to generate code.
[0062] During specific implementation, this embodiment first parses the code template to obtain a parsed code template. Since the code template in this embodiment is generated based on the code type information and the code generation rule corresponding to the code type information is found in the code engine rule library, the code template can generate code corresponding to the code type. The code type is obtained based on business information, so this embodiment inputs the business information into the parsed code template, and the required code can be generated through the parsed code template. When generating the code, this embodiment uses JAVA bytecode and reflection technology to generate it. In addition, this embodiment also pre-sets the code generation save path to store the generated code.
[0063] In summary, the present embodiment first obtains the business information, and determines the code configuration information corresponding to the business type according to the pre-stored correspondence between the business information and the code configuration information. Then, according to the pre-stored correspondence between the code configuration information and the code template, the code template corresponding to the code configuration information is determined. Finally, the code is generated according to the code template and the business information. It can be seen that the present embodiment can obtain the code configuration information corresponding to the business information, and can generate a code template corresponding to the code configuration information. According to the code template, the code that meets the requirements can be generated, which simplifies the traditional code generation process and improves the code generation efficiency.
[0064] Exemplary Devices
[0065] like Figure 5 As shown in , an embodiment of the present invention provides a code generation device, which includes: an information acquisition module 10, a template generation module 20, and a code generation module 30. Specifically, the information acquisition module 10 is used to acquire business information, and determine the code configuration information corresponding to the business type according to the pre-stored correspondence between the business information and the code configuration information. The template generation module 20 is used to determine the code template corresponding to the code configuration information according to the pre-stored correspondence between the code configuration information and the code template. The code generation module 30 is used to generate code according to the code template and the business information.
[0066] In one implementation, the information acquisition module 10 includes:
[0067] A business information acquisition unit, used to acquire business information input by a user;
[0068] A service type acquisition unit, configured to determine the service type corresponding to the service information according to a pre-stored correspondence between the service information and the service type;
[0069] The configuration information acquisition unit is used to determine the code configuration information corresponding to the service type according to the pre-stored correspondence between the service type and the code configuration information.
[0070] In one implementation, the template generation module 20 includes:
[0071] A rule base acquisition unit, used to acquire a preset code engine rule base, wherein the code engine rule base pre-stores a correspondence between the code configuration information and the code template;
[0072] A code template generating unit is used to generate a code template corresponding to the code configuration information according to the code configuration information and the code engine rule base.
[0073] In one implementation, the code generation module 30 includes:
[0074] A code template parsing unit, used to parse the code template to obtain a parsed code template;
[0075] The code generation unit is used to input the business information into the parsed code template to generate code.
[0076] Based on the above embodiments, the present invention further provides an intelligent device, whose principle block diagram can be shown as follows: Figure 6 As shown. The smart device includes a processor, a memory, a network interface, a display screen, and a temperature sensor connected through a system bus. Among them, the processor of the smart device is used to provide computing and control capabilities. The memory of the smart device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the smart device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a code generation method is implemented. The display screen of the smart device can be a liquid crystal display screen or an electronic ink display screen, and the temperature sensor of the smart device is pre-set inside the smart device to detect the operating temperature of the internal device.
[0077] Those skilled in the art will understand that Figure 6 The principle block diagram shown in the figure is only a block diagram of a partial structure related to the solution of the present invention, and does not constitute a limitation on the smart device to which the solution of the present invention is applied. The specific smart device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0078] In one embodiment, a smart device is provided. The smart device includes a memory, a processor, and a batch network configuration program of the smart device stored in the memory and executable on the processor. When the processor executes the batch network configuration program of the smart device, the following operation instructions are implemented:
[0079] Acquire service information, and determine code configuration information corresponding to the service type according to the service information;
[0080] According to the code configuration information, generating a code template corresponding to the code configuration information;
[0081] Generate code according to the code template and the business information.
[0082] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0083] In summary, the present invention discloses a code generation method, device, intelligent terminal and storage medium, the method comprising: first obtaining business information, and determining the code configuration information corresponding to the business type according to the pre-stored correspondence between the business information and the code configuration information. Then, according to the pre-stored correspondence between the code configuration information and the code template, determining the code template corresponding to the code configuration information. Finally, generating code according to the code template and the business information. The present invention can automatically generate a code that meets the requirements according to the business information, avoiding cumbersome steps and improving the efficiency of code generation.
[0084] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A code generation method, characterized in that: The method comprises: Acquire service information, and determine the code configuration information corresponding to the service type according to the pre-stored correspondence between the service information and the code configuration information; Determining a code template corresponding to the code configuration information according to a pre-stored correspondence between the code configuration information and the code template; Generate a code according to the code template and the business information; The acquiring of the service information, and determining the code configuration information corresponding to the service type according to the pre-stored correspondence between the service information and the code configuration information, includes: Get business information entered by the user; Determining the service type corresponding to the service information according to the pre-stored correspondence between the service information and the service type; The determining, according to the pre-stored correspondence between the service information and the service type, the service type corresponding to the service information includes: Parsing the service information to obtain a type identifier in the service information, and then determining a service type corresponding to the service information according to the type identifier, wherein the correspondence between the type identifier and the service type is preset and stored; Determining the code configuration information corresponding to the service type according to the pre-stored correspondence between the service type and the code configuration information; The determining, according to the pre-stored correspondence between the service type and the code configuration information, the code configuration information corresponding to the service type includes: Matching the service type with a preset code database, wherein the code database pre-stores a correspondence between the service type and the code configuration information; Determine the code configuration information corresponding to the service type, the code configuration information including code type information and service component information; The determining, according to the pre-stored correspondence between the code configuration information and the code template, a code template corresponding to the code configuration information includes: Obtaining a preset code engine rule library, wherein the code engine rule library pre-stores a correspondence between the code configuration information and the code template, and the code engine rule library stores generation rules for code templates corresponding to various code types; According to the code configuration information and the code engine rule base, a code template corresponding to the code configuration information is determined.
2. The code generation method according to claim 1, characterized in that: The code type information includes any one of a tool class, an entity class, a data access class, a service class, an interface class, and an implementation layer class.
3. The code generation method according to claim 2, characterized in that: The service component information includes any one of a gateway component, a registration center component, a configuration center component, and a scheduling task center component.
4. The code generation method according to claim 1, characterized in that: The generating of the code according to the code template and the business information includes: Parsing the code template to obtain a parsed code template; The business information is input into the parsed code template to generate code.
5. A code generating device, characterized in that: The device comprises: An information acquisition module, used to acquire service information, and determine the code configuration information corresponding to the service type according to the pre-stored correspondence between the service information and the code configuration information; A template generation module, used to determine a code template corresponding to the code configuration information according to a pre-stored correspondence between the code configuration information and the code template; A code generation module, used to generate code according to the code template and the business information; The acquiring of the service information, and determining the code configuration information corresponding to the service type according to the pre-stored correspondence between the service information and the code configuration information, includes: Get business information entered by the user; Determining the service type corresponding to the service information according to the pre-stored correspondence between the service information and the service type; The determining, according to the pre-stored correspondence between the service information and the service type, the service type corresponding to the service information includes: Parsing the service information to obtain a type identifier in the service information, and then determining a service type corresponding to the service information according to the type identifier, wherein the correspondence between the type identifier and the service type is preset and stored; Determining the code configuration information corresponding to the service type according to the pre-stored correspondence between the service type and the code configuration information; The determining, according to the pre-stored correspondence between the service type and the code configuration information, the code configuration information corresponding to the service type includes: Matching the service type with a preset code database, wherein the code database pre-stores a correspondence between the service type and the code configuration information; Determine the code configuration information corresponding to the service type, the code configuration information including code type information and service component information; The determining, according to the pre-stored correspondence between the code configuration information and the code template, a code template corresponding to the code configuration information includes: Obtaining a preset code engine rule library, wherein the code engine rule library pre-stores a correspondence between the code configuration information and the code template, and the code engine rule library stores generation rules for code templates corresponding to various code types; According to the code configuration information and the code engine rule base, a code template corresponding to the code configuration information is determined.
6. A smart device, characterized in that: The smart device includes a memory, a processor, and a code generation program stored in the memory and executable on the processor. When the processor executes the code generation program, the steps of the code generation method according to any one of claims 1 to 4 are implemented.
7. A computer-readable storage medium, characterized in that: A code generation program is stored thereon, and when the code generation program is executed by a processor, the steps of the code generation method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Template based rear-end code generation method and system
CN108228166A
Code structure generation method and device, computer device and readable storage medium
CN109947399A
Software code generation method and device, computer equipment and storage medium
CN111061475A
Construction and use method of software development framework, computing device and storage medium
CN111190586A