Code generation method and device and storage medium
By converting text data into metadata objects and combining them with preset code templates and patterns, code files are automatically generated and integrated, solving the problem of low efficiency in traditional code generation and achieving efficient, seamless code integration and smooth development.
Patent Information
- Application Number
- CN202511441604.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-10
- Publication Date
- 2026-01-23
AI Technical Summary
Traditional code generation methods are inefficient, especially in the middle of a project where it is difficult to automatically generate and integrate new code files, resulting in poor development smoothness and a high risk of errors.
By converting text data into metadata objects and combining them with preset code templates and patterns, target code files are automatically generated, and precise insertion and configuration updates are performed at specified locations, achieving automated code generation and integration.
It improved coding efficiency, reduced manual configuration time, avoided errors, and enabled seamless integration and rapid development of new functional modules.
Smart Images

Figure CN121387296A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, and in particular, to a code generation method and device and storage medium. BACKGROUND
[0002] In the development practice of a software system, a traditional code implementation mode relies on manual coding. However, some codes have similar logic and need to be repeatedly coded, which leads to low development efficiency of manual coding. Therefore, how to improve the coding efficiency has become a technical problem to be solved. SUMMARY
[0003] The present application aims to provide a code generation method and device and storage medium, and aims to solve the problem of low coding efficiency.
[0004] To achieve the above-mentioned purpose, in a first aspect, the present application provides a code generation method, which comprises: obtaining text data, the text data comprising: a function identifier, the function identifier being used to reflect a target function implemented by the text data, and the text data being used to describe code required for implementing the target function; performing data structure conversion on the text data to obtain a metadata object; generating initial code based on the metadata object and a preset code template file, the initial code comprising: the function identifier; and generating a target code file based on a preset code mode and the initial code, the target code file being used to implement the target function, the preset code mode being used to indicate a generation position of the target code file, and the generation position comprising: a preset generation position and a target project running position, the target project running position being used to run code data in the target code file.
[0005] Based on the above technical solution, by performing data structure conversion on the text data to obtain a metadata object, and generating initial code based on the metadata object and a preset code template file, the preliminary generation of code can be completed. Then, based on a preset code mode and the initial code, a target code file can be generated, so that the generation position of the target code file can be determined, and the target code file can be generated at the corresponding position, thereby realizing the automatic generation of the code file and improving the coding efficiency. At the same time, by setting two generation positions, the code file can be flexibly generated to meet the diversified needs of users.
[0006] In some embodiments, the preset code mode comprises: a file generation mode and a project insertion mode, the file generation mode being used to indicate that the target code file is generated at the preset generation position, and the project insertion mode being used to indicate that the target code file is generated at the target project running position.
[0007] In some embodiments, the method further includes: in response to a mode selection operation of the preset code mode by the user, obtaining a mode selection instruction. In a case where the mode selection instruction is used to indicate the project insertion mode, obtaining a target file path based on a preset file path and function identifier correspondence relationship, the target file path being used to indicate a target project running position of the target code file, the preset file path and function identifier correspondence relationship being a correspondence relationship between a preset file path and a preset function identifier, the preset function identifier including the function identifier, and the preset file path including the target file path. Generating the target code file in the target project running position based on the target file path.
[0008] In some embodiments, the method further includes: in a case where the mode selection instruction is used to indicate the file generation mode, generating the target code file in a preset generation position.
[0009] In some embodiments, after the target code file is generated in the target project running position based on the target file path, the method further includes: obtaining a configuration file, the configuration file being used to determine a position of the target code file. Updating the configuration file based on the target code file to obtain an updated configuration file. Storing the updated configuration file in an initial storage position, the initial storage position being a storage position of the configuration file before the configuration file is updated.
[0010] In some embodiments, the configuration file includes a routing configuration file, the routing configuration file including a routing object array, the routing array including a correspondence relationship between a path of all code files in the project and a page component, the page component being an independent code unit encapsulating a page function. Updating the configuration file based on the target code file includes: obtaining a target page component corresponding to the target code file based on the target code file. Updating the routing array based on the target file path and the target page component.
[0011] In some embodiments, the configuration file includes a backend configuration file, the backend configuration file being used to indicate a correspondence relationship between a backend interface and a file path. Updating the configuration file based on the target code file includes: obtaining a target backend interface corresponding to the target code file based on the target code file, the target backend interface being used to transmit data corresponding to the target code file. Updating the backend configuration file based on the target backend interface and the target file path.
[0012] In some embodiments, the configuration file includes a menu configuration file, the menu configuration file being used to indicate a correspondence relationship between a menu label and a file path. Updating the configuration file based on the target code file includes: obtaining a target menu label corresponding to the target code file based on the target code file, the menu label being used to indicate a function corresponding to the target code file. Updating the menu configuration file based on the target menu label and the target file path.
[0013] In a second aspect, the present application provides a code generation apparatus, comprising an obtaining module and a processing module.
[0014] The obtaining module is configured to obtain text data, the text data comprising a function identifier, the function identifier being used to reflect a target function implemented by the text data, and the text data being used to describe code required for implementing the target function. The processing module is configured to perform data structure conversion on the text data to obtain a metadata object. The processing module is further configured to generate initial code based on the metadata object and a preset code template file, the initial code comprising the function identifier. The processing module is further configured to generate a target code file based on a preset code mode and the initial code, the target code file being used to implement the target function, and the preset code mode being used to indicate a generation position of the target code file, the generation position comprising a preset generation position and a target project running position, and the target project running position being used to run code data in the target code file.
[0015] In some embodiments, the preset code mode comprises a file generation mode and a project insertion mode, the file generation mode being used to indicate generation of the target code file at the preset generation position, and the project insertion mode being used to indicate generation of the target code file at the target project running position.
[0016] In some embodiments, the obtaining module is configured to obtain a mode selection instruction in response to a mode selection operation of a user on the preset code mode. The processing module is configured to obtain a target file path based on a correspondence between the function identifier and a preset file path in a case where the mode selection instruction is used to indicate the project insertion mode, the target file path being used to indicate the target project running position at which the target code file is generated, the correspondence between the preset file path and the preset function identifier being a correspondence between a preset file path and a preset function identifier, the preset function identifier comprising the function identifier, and the preset file path comprising the target file path. The processing module is further configured to generate the target code file at the target project running position based on the target file path.
[0017] In some embodiments, the processing module is configured to generate the target code file at the preset generation position in a case where the mode selection instruction is used to indicate the file generation mode.
[0018] In some embodiments, the obtaining module is configured to obtain a configuration file, the configuration file being used to determine a position of the target code file. The processing module is configured to update the configuration file based on the target code file to obtain an updated configuration file. The processing module is further configured to store the updated configuration file at an initial storage position, the initial storage position being a storage position of the configuration file before the configuration file is updated.
[0019] In some embodiments, the configuration file comprises: a routing configuration file, the routing configuration file comprising: a routing object array, the routing array comprising: a correspondence between paths of all code files in the project and page components, the page components being independent code units encapsulating page functions; and a processing module configured to obtain, based on a target code file, a target page component corresponding to the target code file; and update, based on the target file path and the target page component, the routing array.
[0020] In some embodiments, the configuration file comprises: a backend configuration file, the backend configuration file being configured to indicate a correspondence between backend interfaces and file paths; and a processing module configured to obtain, based on a target code file, a target backend interface corresponding to the target code file, the target backend interface being configured to transmit data corresponding to the target code file; and update, based on the target backend interface and the target file path, the backend configuration file.
[0021] In some embodiments, the configuration file comprises: a menu configuration file, the menu configuration file being configured to indicate a correspondence between menu labels and file paths; and a processing module configured to obtain, based on a target code file, a target menu label corresponding to the target code file, the menu label being configured to indicate a function corresponding to the target code file; and update, based on the target menu label and the target file path, the menu configuration file.
[0022] In a third aspect, the present application provides a code generation apparatus, comprising: a processor and a memory; the processor and the memory are coupled; the memory is configured to store one or more programs, the one or more programs comprising computer execution instructions; when the code generation apparatus is running, the processor executes the computer execution instructions stored in the memory to implement the method described in the first aspect and any possible implementation manner of the first aspect.
[0023] In a fourth aspect, the present application provides a computer readable storage medium, the computer readable storage medium storing instructions, when the instructions are running on a computer, causing the computer to execute the method described in the first aspect and any possible implementation manner of the first aspect.
[0024] In a fifth aspect, the present application provides a chip, the chip comprising a processor and a communication interface, the communication interface and the processor being coupled, the processor being configured to run a computer program or instructions to implement the method described in the first aspect and any possible implementation manner of the first aspect.
[0025] In a sixth aspect, the present application provides a computer program product comprising instructions, when the instructions are running on a computer, causing the computer to execute the method described in the first aspect and any possible implementation manner of the first aspect.
[0026] The technical problems and technical effects solved by the code generation apparatus, the computer device, the computer storage medium, the chip, or the computer program product in the above solutions can refer to the technical problems and technical effects solved by the first aspect, which will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS
[0027] Various other advantages and benefits will become apparent to those of ordinary skill in the art, upon reading the following detailed description of the preferred embodiments. The accompanying drawings are intended to further aid the full and complete understanding of the preferred embodiments. The drawings are merely schematic and are not necessarily drawn to scale. Throughout the drawings, the same reference numerals are used for like components. In the drawings: Figure 1 A system architecture diagram of a code generation system provided by an embodiment of the present application; Figure 2 A flowchart of a code generation method provided by an embodiment of the present application; Figure 3 A structural diagram of a code generation apparatus provided by an embodiment of the present application; Figure 4 A structural diagram of another code generation apparatus provided by an embodiment of the present application; Figure 5 A conceptual partial view of a computer program product provided by an embodiment of the present application. DETAILED DESCRIPTION
[0028] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0029] In the description of the present application, it should be understood that the terms “upper”, “lower”, “left”, “right”, “front”, “back”, “inner”, “outer” and the like indicate the orientation or positional relationship based on the orientation or relative position relationship shown in the drawings, and are only intended to facilitate the description of the present application and simplify the description, and do not indicate or imply that the device or element referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation on the present application. Unless otherwise specified, the above directional description can be flexibly arranged in the process of actual application, as long as the relative positional relationship shown in the drawings is met.
[0030] The terms "first", "second", etc. are used only to describe purposes and can not be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the present application, unless otherwise specified, the meaning of "a plurality of" is two or more.
[0031] In the embodiments of the present application, the terms "comprising", "containing" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, article or device. Without more limitations, the element defined by the sentence "including a" does not exclude the presence of other identical elements in the process, article or device including the element.
[0032] In the embodiments of the present application, the words such as "exemplary" or "for example" are used to represent as an example, illustration or description. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as more preferred or more advantageous than other embodiments or design schemes. Rather, the words such as "exemplary" or "for example" are intended to present the relevant concept in a specific manner.
[0033] In the field of software development, the code generated by the traditional code generator needs a lot of manual copy, paste and configuration modification work to complete the function integration, and the whole process is inefficient. In order to reduce repetitive coding work, code generation tools have emerged. Among them, code generation tools include file-level code generator and project-level code generator / low-code platform.
[0034] The file-level code generator can be a tool such as MyBatis-Plus Generator, which can generate corresponding Java files of entity class (i.e. Entity), data access object layer (i.e. Mapper / Data Access Object Layer (DAO), service layer (i.e. Service) and control layer (i.e. Controller) according to the database table.
[0035] File-level code generators can generate code files simply and directly, but only generate isolated code files. Therefore, developers need to manually copy these generated code files into the correct directory of the project and manually complete a series of tedious integration work. For example: adding a new page (such as a.vue file) in the front-end project, registering the path of the new page in the routing file (such as router.js), adding an entry in the navigation menu component, defining the interface in the Application Programming Interface (API) management file, etc.
[0036] That is, when the file-level code generator needs to manually modify the front-end routing, menu, backend configuration, etc. files, it is easy to cause path errors, syntax errors or component registration omissions due to negligence, thereby causing the application to fail to start or abnormal functions. Therefore, the configuration of the code file is time-consuming, repetitive and prone to errors.
[0037] Although project-level code generators / low-code platforms (such as JHipster, Jeecg-Boot, RuoYi, etc.) can generate a complete and runnable front-end and back-end project, these platforms are usually used for the initial creation of the project. When the project has entered the middle stage of development and the developer needs to add one or more CRUD modules, the process of automatically generating code files using the project-level code generator / low-code platform will be relatively complex. In this process, it is usually necessary to re-run the generator and manually compare and merge new and old code, or the process of incrementally adding new modules is not automated enough.
[0038] That is, manual intervention is still needed to adjust the configuration in this process. The core mode of the project-level code generator / low-code platform is to generate a completely new project, which is difficult to seamlessly insert a new code file into an existing project.
[0039] Therefore, the traditional technology either only generates code files and cannot configure files, or can only generate a complete project at the initial stage of the project. In this way, the smoothness of development is destroyed, and it is impossible to automatically realize a runnable function point from a data model. Moreover, neither of these two methods is automated and lightweight enough to be applied to incremental development in the middle stage of the project.
[0040] To solve the above technical problems, an embodiment of the present application provides a code generation method. In the method, the text data is converted into a data structure to obtain a metadata object, and an initial code is generated based on the metadata object and a preset code template file, so that the preliminary generation of the code can be completed. Then, a target code file can be generated based on the preset code mode and the initial code, so that the generation position of the target code file can be determined, and the target code file can be generated at the corresponding position, thereby realizing automatic generation of the code file and improving the efficiency of writing the code. Meanwhile, by setting two generation positions, the code file can be flexibly generated to meet the diversified needs of users.
[0041] The implementation environment of the embodiment of the present application is introduced below.
[0042] As shown in Figure 1 The present application provides a code generation system, which comprises a metadata analysis module, a code generation module and an output strategy module.
[0043] The metadata analysis module is used to analyze the text data to obtain a metadata object.
[0044] The code generation module is used to generate an initial code based on the metadata object and a preset code template file.
[0045] The output strategy module is used to determine the position of generating a target code file.
[0046] The output strategy module comprises a file generation module and a project insertion module. The file generation module is used to generate the target code file at a preset generation position, and the project insertion module is used to instruct to generate the target code file at a target project running position of a scaffold project.
[0047] Optionally, the project insertion module comprises a file copying module, a front-end configuration modification module and a back-end configuration modification module.
[0048] The file copying module is used to copy the target code file at the target project running position, the front-end configuration modification module is used to modify the configuration file of the front end, and the back-end configuration modification module is used to modify the configuration file of the back end.
[0049] The embodiment of the present application is described below in combination with the drawings of the specification.
[0050] As shown in Figure 2 A code generation method provided by an embodiment of the present application comprises: S201, obtaining text data.
[0051] The text data comprises a function identifier, and the function identifier is used to reflect the target function implemented by the text data.
[0052] The present application does not limit the text data. For example, the text data can be data definition language (DDL) text, natural language description text, or API text. The present application does not limit the function identifier. For example, the function identifier can be a table name of the text data.
[0053] In a possible implementation, in response to a text input operation of a user, the DDL text can be obtained.
[0054] In another possible implementation, a connection with the database can be established through a target database interface. Then, the DDL text in the database can be obtained by calling the target database interface.
[0055] The target database interface is configured to interact with the database.
[0056] The present application does not limit the target database interface. For example, the target database interface can be a Java database connectivity (JDBC) interface.
[0057] In this way, by reading the database table structure or directly parsing the DDL statement, the standardized backend (i.e., Spring Boot) and frontend (i.e., Vue.js) CRUD (i.e., Create, Read, Update, and Delete) files can be automatically generated.
[0058] S202. Perform data structure conversion on the text data to obtain a metadata object.
[0059] The metadata object is configured to describe code required to implement a target function.
[0060] In a possible implementation, the text data can be parsed by a structured query language (SQL) parser to obtain an abstract syntax tree (AST). Then, semantic analysis can be performed on the AST to extract semantic information from the AST. Then, the metadata object can be obtained based on the semantic information.
[0061] Optionally, the semantic information includes at least one of the following: a table name, a field name, a data type, a primary key, and a comment.
[0062] The metadata object is an object encapsulating semantic information in a program.
[0063] S203. Generate initial code based on the metadata object and a preset code template file.
[0064] The initial code includes a function identifier.
[0065] In a possible implementation, the metadata object and the preset code template file can be rendered by a FreeMarker template engine to obtain the initial code.
[0066] The number of preset code template files is multiple, and the multiple preset code template files are a series of template files written in advance. For example, the preset code template file can be controller.java.ftl, service.java.ftl, or page.vue.ftl.
[0067] In this way, the multi-layer front-end code from interface rendering (i.e., a basic resource layer) to user interaction (i.e., a component layer and a routing layer), and then to data communication (i.e., an interface layer) can be generated by rendering. The multi-layer back-end code from database operation (i.e., a Data Access Object Layer (DAO)) to business logic (i.e., a Service layer), and then to interface exposure (i.e., a Controller layer) can also be generated by rendering.
[0068] S204, generating a target code file based on the preset code mode and the initial code.
[0069] The target code file is used to implement a target function, and the preset code mode is used to indicate a generation position of the target code file. The generation position includes a preset generation position and a target project running position, and the target project running position is used to run code data in the target code file.
[0070] Optionally, the preset code mode includes a file generation mode and a project insertion mode. The file generation mode is used to indicate that the target code file is generated at the preset generation position, and the project insertion mode is used to indicate that the target code file is generated at the target project running position.
[0071] In a possible implementation, in response to a mode selection operation of the preset code mode by a user, a mode selection instruction can be obtained. Then, in a case where the mode selection instruction indicates the project insertion mode, a target file path can be obtained based on a preset file path correspondence relationship. The target file path is used to indicate a target project running position where the target code file is generated, the preset file path correspondence relationship is a correspondence relationship between a preset file path and a preset function identifier, the preset function identifier includes the function identifier, and the preset file path includes the target file path. Then, the target code file can be generated at the target project running position based on the target file path.
[0072] For example, the function of the Controller file is identified as Controller, and the Controller file can be placed in the src / main / java / ... / controller directory. The function of the Vue page file is identified as Vue, and the Vue file can be placed in the src / views / system / ... directory.
[0073] In this way, the generated code file can be accurately copied to the corresponding position of the scaffold project.
[0074] In another possible implementation, in a case where the mode selection instruction is used to indicate a file generation mode, the target code file is generated at a preset generation position.
[0075] In this way, the generated initial code is directly written into the output directory specified by the user, and a series of independent Java source code files (i.e., source code files with the.java extension), UI component implementation files of the front-end framework Vue.js (i.e., source code files with the.vue extension), and extensible markup language files (i.e., source code files with the.xml extension) are generated.
[0076] Based on the above technical solution, the text data is converted into a data structure to obtain a metadata object, and the initial code is generated based on the metadata object and a preset code template file, so that the preliminary generation of the code can be completed. Then, the target code file can be generated based on the preset code mode and the initial code, so that the generation position of the target code file can be determined, and the target code file can be generated at the corresponding position, thereby realizing the automatic generation of the code file and improving the efficiency of writing the code. At the same time, by setting two generation positions, the code file can be flexibly generated to meet the diversified needs of users.
[0077] In some embodiments, after the target code file is generated at the target project running position based on the target file path, a configuration file can be obtained, the configuration file being used to determine the position of the target code file. Then, the configuration file can be updated based on the target code file to obtain an updated configuration file. Then, the updated configuration file can be stored again in the initial storage position, which is the storage position of the configuration file before the configuration file is updated.
[0078] Optionally, the configuration file includes a routing configuration file, and the routing configuration file includes a routing object array, and the routing array includes a corresponding relationship between the paths of all code files in the project and page components, and the page component is an independent code unit encapsulating page functions.
[0079] In a possible design, a target page component corresponding to the target code file can be obtained based on the target code file. Then, the routing array can be updated based on the target file path and the target page component.
[0080] Specifically, the code text in the routing configuration file of the front end can be converted into a routing AST by an AST parser, the routing AST including a routing array node, the routing array node being the converted routing array, the routing array node including a routing array list, the routing array list including a plurality of object nodes. Then, a target page component corresponding to the target code file can be obtained based on the target code file. Then, a target object node can be constructed based on the target file path and the target page component. Then, the target object node can be added at the end of the routing array list to obtain an updated routing AST. Then, the updated routing AST can be converted into a JavaScript code, and the source code of the front-end routing configuration file can be overwritten based on the JavaScript code to update the routing array.
[0081] In this way, the routing array can be updated more safely and accurately.
[0082] If the storage location of the Mapper interface or the mapping file does not comply with the path rules agreed by default by the framework, the backend configuration file needs to be updated.
[0083] Optionally, the configuration file further includes a backend configuration file, the backend configuration file being used to determine a target backend interface corresponding to the target code file.
[0084] In another possible design, a target backend interface corresponding to the target code file can be obtained based on the target code file, the target backend interface being used to transmit data corresponding to the target code file. Then, a backend configuration file can be updated based on the target backend interface and the target file path.
[0085] For example, the backend configuration file is a MyBatis configuration file.
[0086] Specifically, an Extensible Markup Language (XML) text in a MyBatis configuration file can be acquired, and the XML text can be converted into a configuration tree based on an XML parser, an XML tag in the XML text is converted into a tag node, the configuration tree includes an interface parent node, the interface parent node includes a tag node list, and the tag node list includes a plurality of tag nodes. Then, a target backend interface corresponding to the target code file can be obtained based on the target code file. Then, a target tag node can be created based on the target backend interface and the target file path. Then, the target tag node can be added at the end of the tag node list to obtain an updated configuration tree. Then, the updated configuration tree can be converted into an XML code, and the XML code can be written into the XML text in the MyBatis configuration file based on the XML code to obtain an updated backend configuration file.
[0087] For example, the MyBatis configuration file can be mybatis-config.xml.
[0088] Optionally, the configuration file further includes a menu configuration file, and the menu configuration file is used to indicate a corresponding relationship between a menu tag and a file path.
[0089] In another possible design, a target menu tag corresponding to the target code file can be obtained based on the target code file, and the menu tag is used to indicate a function corresponding to the target code file. Then, the menu configuration file can be updated based on the target menu tag and the target file path.
[0090] For example, the menu configuration file can be a template file of a navigation menu component.
[0091] Specifically, a template file of a navigation menu component can be acquired, and code in the template file can be converted into a menu tree structure, the menu tree structure includes a target menu node, the target menu node includes a menu item node list, and the menu item node list includes a plurality of menu item nodes. Then, a target menu tag corresponding to the target code file can be obtained based on the target code file. Then, a target menu item node can be created based on the target menu tag and the target file path. Then, the target menu item node can be added at the end of the menu item node list to obtain an updated menu tree structure. Then, the updated menu tree structure can be converted into an HTML string, and the code in the template file can be written based on the HTML string to obtain an updated template file of the navigation menu component.
[0092] The template file of the navigation menu component includes a plurality of menu tabs. The template file of the navigation menu component can be src / layout / components / Sidebar.vue, and the menu tabs can be <el-menu-item>.
[0093] Thus, in the project insertion mode, the generated target code file can be automatically inserted into the corresponding position of the target scaffold project, and the configuration files such as front-end routing and menu navigation are intelligently modified, the whole link from the database table structure to the executable function module is opened, and finally the newly generated function module is seamlessly integrated into the existing project. The developer does not need to care about the tedious configuration details, and can immediately start the project for testing and verification after generation, and the experience is extremely smooth. Moreover, the integration work that needs to be done manually can be completely automated, and the developer only needs to provide the table structure to obtain a complete, usable and error-free new function module in a few seconds. This greatly reduces the time spent on CRUD functions, avoids human errors caused by manual configuration, and improves development efficiency.
[0094] Thus, the present application can increase the perception and programmatic modification capability of the target scaffold project structure on the basis of traditional code generation by designing a code generation engine containing a preset code pattern.
[0095] The above mainly introduces the scheme provided by the embodiments of the present application from the perspective of the method. It can be understood that the code generation device contains the hardware structure and / or software module corresponding to the execution of each function in order to implement the above functions. Those skilled in the art should easily realize that the code generation method steps of each example described in combination with the embodiments disclosed in the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0096] The embodiments of the present application also provide a code generation device. The code generation device can be a server, a CPU in the above-mentioned server, a code generation module in the above-mentioned server, or a client for generating code in the above-mentioned server.
[0097] The embodiments of the present application can divide the code generation device into functional modules or functional units according to the above-mentioned method examples, for example, each functional module or functional unit can be divided according to each function, or two or more functions can be integrated in one processing module. The above-mentioned integrated module can be realized in the form of hardware or software functional module or functional unit. Among them, the division of modules or units in the embodiments of the present application is illustrative, and is only a logical functional division. When actually implemented, there can be another division method.
[0098] The embodiment of the present application provides a code generation device. As shown in the figure, the code generation device can comprise an acquisition module 301 and a processing module 302. Figure 3
[0099] The acquisition module 301 is used for acquiring text data, wherein the text data comprises a function identifier, the function identifier is used for reflecting a target function implemented by the text data, and the text data is used for describing code required for implementing the target function.
[0100] The processing module 302 is used for performing data structure conversion on the text data to obtain a metadata object. The processing module is also used for generating initial code based on the metadata object and a preset code template file, wherein the initial code comprises the function identifier. The processing module 302 is also used for generating a target code file based on a preset code mode and the initial code, wherein the target code file is used for implementing the target function, the preset code mode is used for indicating a generation position of the target code file, and the generation position comprises a preset generation position and a target project running position, and the target project running position is used for running code data in the target code file.
[0101] Figure 4 The structure diagram of another code generation device provided by the embodiment of the present application is provided. The code generation device can comprise a processor 402, and the processor 402 is used for executing application program code, so as to implement the code generation method in the present application.
[0102] The processor 402 can be a central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.
[0103] As shown in the figure, the code generation device can further comprise a memory 403. The memory 403 is used for storing the application program code for executing the program of the present application, and the execution is controlled by the processor 402. Figure 4
[0104] Memory 403 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. Memory 403 may exist independently and be connected to processor 402 via bus 404. Memory 403 may also be integrated with processor 402.
[0105] like Figure 4 As shown, the code generation device may further include a communication interface 401, wherein the communication interface 401, processor 402, and memory 403 may be coupled to each other, for example, through a bus 404. The communication interface 401 is used for information interaction with other devices, for example, supporting information interaction between the code generation device and other devices.
[0106] It should be pointed out that, Figure 4 The device structure shown does not constitute a limitation on the code generation device, except Figure 4 In addition to the components shown, the code generation apparatus may include more or fewer components than illustrated, or combine certain components, or have different component arrangements.
[0107] In actual implementation, the functions implemented by processing module 302 can be provided by... Figure 4 The processor 402 shown calls the program code in memory 403 to implement this.
[0108] This application also provides a computer-readable storage medium storing instructions that, when executed by a processor of a computer device, enable the computer to perform the code generation method provided in the embodiments described above. For example, the computer-readable storage medium may be a memory 403 including instructions, which may be executed by a processor 402 of a computer device to complete the method. Optionally, the computer-readable storage medium may be a non-transitory computer-readable storage medium, such as a ROM, RAM, CD-ROM, magnetic tape, floppy disk, or optical data storage device.
[0109] Figure 5 This is a conceptual partial view of a computer program product provided in an embodiment of this application. The computer program product includes a computer program for executing computer processes on a computing device.
[0110] In one embodiment, a computer program product is provided using a signal bearer medium 500. The signal bearer medium 500 may include one or more program instructions that, when executed by one or more processors, can provide the above-mentioned... Figure 2 The described function or part of the function. Therefore, for example, refer to... Figure 2 In the embodiment shown, one or more features of S201-S204 can be fulfilled by one or more instructions associated with the signal carrying medium 500. Furthermore, Figure 5 The program instructions in the document also describe example instructions.
[0111] In some examples, the signal carrying medium 500 may include a computer-readable medium 501, such as, but not limited to, a hard disk drive, a compact disc (CD), a digital video disc (DVD), a digital magnetic tape, a memory, a read-only memory (ROM), or a random access memory (RAM), and so on.
[0112] In some implementations, the signal carrying medium 500 may include a computer recordable medium 502, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, and so on.
[0113] In some implementations, the signal carrying medium 500 may include a communication medium 503, such as, but not limited to, digital and / or analog communication media (e.g., fiber optic cables, waveguides, wired communication links, wireless communication links, etc.).
[0114] The signal-bearing medium 500 can be conveyed by a wireless form of the communication medium 503. The one or more program instructions can be, for example, computer-executable instructions or logic-implementing instructions.
[0115] In some examples, the code generation apparatus can be configured to provide various operations, functions, or actions in response to the one or more program instructions of the computer-readable medium 501, the computer-recordable medium 502, and / or the communication medium 503.
[0116] From the above description of the embodiments, it is apparent that for the convenience and conciseness of description, only the division of the above functional modules is taken as an example for description, and in actual application, the above functions can be completed by different functional modules, i.e., the internal structure of the apparatus is divided into different functional modules to complete the full classification or part of the functions described above.
[0117] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. For example, the apparatus embodiment described above is only illustrative, for example, the division of the module or unit is only a logical function division, and in actual implementation, another division mode can be used, for example, a plurality of units or components can be combined or integrated into another apparatus, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or components shown or discussed can be indirect coupling or communication connection through some interfaces, apparatuses or units, which can be electrical, mechanical or other forms.
[0118] The units described as separate components can or can not be physically separated, and the components shown as units can be one physical unit or multiple physical units, i.e., can be located in one place or can be distributed to multiple different places. Part or all of the classification units can be selected according to actual needs to achieve the purpose of the embodiment.
[0119] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0120] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application essentially or say the part that contributes to the prior art or the whole classification part or part of the technical solutions can be embodied in the form of a software product. The software product is stored in a storage medium, including a plurality of instructions to make a device (which can be a single-chip microcomputer, a chip, etc.) or a processor (processor) execute the whole classification part or part of the steps of the method of each embodiment of the present application. The aforementioned storage medium includes a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk, and various storage program codes.
[0121] The above is only a specific embodiment of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A code generation method characterized by, The method comprises: acquiring text data, the text data comprising: a function identifier, the function identifier reflecting a target function implemented by the text data, the text data describing code required for implementing the target function; performing data structure conversion on the text data to obtain a metadata object; generating initial code based on the metadata object and a preset code template file, the initial code comprising: a function identifier; generating a target code file based on a preset code mode and the initial code, the target code file being used to implement the target function, the preset code mode being used to indicate a generation position of the target code file, the generation position comprising: a preset generation position and a target project running position, the target project running position being used to run code data in the target code file.
2. The method of claim 1, wherein, The preset code mode comprises: a file generation mode and a project insertion mode, the file generation mode being used to indicate generation of the target code file at the preset generation position, and the project insertion mode being used to indicate generation of the target code file at the target project running position.
3. The method of claim 2, wherein, The generating of the target code file based on the preset code mode and the initial code comprises: in response to a mode selection operation of a user on the preset code mode, acquiring a mode selection instruction; in a case where the mode selection instruction indicates the project insertion mode, obtaining a target file path based on a preset file path correspondence relationship, the target file path being used to indicate a target project running position of generation of the target code file, the preset file path correspondence relationship being a correspondence relationship between a preset file path and a preset function identifier, the preset function identifier comprising: the function identifier, and the preset file path comprising: the target file path; generating the target code file at the target project running position based on the target file path.
4. The method of claim 3, wherein, The method further comprises: in a case where the mode selection instruction indicates the file generation mode, generating the target code file at the preset generation position.
5. The method of claim 3, wherein, After the generating of the target code file at the target project running position based on the target file path, the method further comprises: acquiring a configuration file, the configuration file being used to determine a position of the target code file; updating the configuration file based on the target code file to obtain an updated configuration file; storing the updated configuration file in an initial storage position, the initial storage position being a storage position of the configuration file before the updating of the configuration file.
6. The method of claim 5, wherein, The configuration file comprises: a routing configuration file, the routing configuration file comprising: a routing object array, the routing array comprising: a correspondence relationship between paths of all code files in a project and page components, the page components being independent code units encapsulating page functions; The updating of the configuration file based on the target code file comprises: obtaining a target page component corresponding to the target code file based on the target code file; updating the routing array based on the target file path and the target page component.
7. The method of claim 5, wherein, The configuration file comprises: a backend configuration file, the backend configuration file being used to indicate a correspondence between a backend interface and a file path; and the updating the configuration file based on the target code file comprises: obtaining a target backend interface corresponding to the target code file based on the target code file, the target backend interface being used to transmit data corresponding to the target code file; and updating the backend configuration file based on the target backend interface and the target file path.
8. The method of claim 5, wherein, The configuration file comprises: a menu configuration file, the menu configuration file being used to indicate a correspondence between a menu label and a file path; and the updating the configuration file based on the target code file comprises: obtaining a target menu label corresponding to the target code file based on the target code file, the menu label being used to indicate a function corresponding to the target code file; and updating the menu configuration file based on the target menu label and the target file path.
9. A code generating apparatus characterized by comprising: comprise: a processor and a memory; the processor and the memory are coupled; the memory is used to store one or more programs, the one or more programs comprising computer execution instructions, when the grounding body evaluation device is running, the processor executes the computer execution instructions stored in the memory, so that the grounding body evaluation device executes the method according to any one of claims 1-8.
10. A computer-readable storage medium having stored therein instructions, the computer-readable storage medium comprising: When the computer executes the instructions, the computer executes the method according to any one of claims 1-8.