Code generation method, device, equipment and storage medium

By using flexible code generation templates and template mapping rules, logic code is automatically generated, solving the problems of high code maintenance costs and low efficiency in existing technologies. This achieves reusability and standardization of the code generation process, improving development efficiency and system adaptability.

CN119847499BActive Publication Date: 2025-10-28APPEON TECH SZ LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411887206.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-18
Publication Date
2025-10-28
Estimated Expiration
2044-12-18

AI Technical Summary

Technical Problem

In existing technologies, developers need to manually write code to cope with changes in business requirements, resulting in high code maintenance costs, low efficiency, and difficulty in adapting to complex and multi-layered nested metadata structures.

Method used

By using flexible code generation templates and template mapping rules, logical code can be automatically generated. By leveraging the mapping relationship between code generation templates and metadata, changes in business requirements can be responded to simply by updating the templates or metadata, thus decoupling the metadata structure from the generated code logic.

Benefits of technology

It achieves reusability and standardization of the code generation process, reduces maintenance costs, improves development efficiency and system adaptability, and reduces repetitive work and the tedium of code modification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847499B_ABST
    Figure CN119847499B_ABST
Patent Text Reader

Abstract

This application discloses a code generation method, apparatus, device, and storage medium to improve the flexibility and adaptability of code generation. The method includes: obtaining a code generation template set for business requirements; determining metadata associated with the code generation template according to template mapping rules; and generating logical code corresponding to the metadata based on the code generation template and the associated metadata. By implementing the method of this application, when business requirements change, only the template or metadata needs to be updated, without rewriting the code. Business requirements in different scenarios can be dynamically generated using templates, thereby significantly improving adaptability and versatility. Furthermore, after the template, mapping rules, and metadata are configured, the code generation process can be highly automated, effectively reducing repetitive work for developers and improving development efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to code generation methods, apparatus, devices and storage media. Background Technology

[0002] As software development becomes increasingly complex, developers need to quickly generate code logic based on business requirements to meet development needs in different scenarios. To solve the problem of repetitive work and improve code development efficiency, code generation technology has gradually become an important tool in the development process.

[0003] In related technologies, developers typically manually write logic and concatenate it with data sources to generate business code. This string concatenation method is simple and intuitive, but as the business scales up, code maintenance and modification become complex and error-prone. Once requirements change, developers usually need to significantly modify the code, leading to high maintenance costs and low efficiency. Summary of the Invention

[0004] To address the aforementioned issues, embodiments of this application provide a code generation method, apparatus, device, and storage medium, with the aim of achieving reusability and standardization of the code generation process, reducing maintenance costs, and enhancing scalability.

[0005] In a first aspect, embodiments of this application provide a code generation method, including:

[0006] Get the code generation template that corresponds to the business requirements;

[0007] Based on the template mapping rules, determine the metadata associated with the code generation template;

[0008] Based on the code generation template, logical code corresponding to the metadata associated with the code generation template is generated.

[0009] In one embodiment, the template mapping rule is a mapping relationship between the data source of the code generation template and the type of the metadata.

[0010] In one embodiment, the metadata further includes a root node and multi-level nested child nodes. The step of generating logical code corresponding to the metadata based on the code generation template, using the metadata associated with the code generation template, includes:

[0011] Based on the data splitting tags of the code generation template, traverse each of the child nodes in the metadata associated with the code generation template;

[0012] Each of the child nodes is split and processed to obtain at least one sub-data element corresponding to each child node;

[0013] Based on the root node, at least one root metadata corresponding to the root node is obtained;

[0014] Based on the type of the sub-database and the type of the root metadata, code generation templates corresponding to the type of the sub-database and the type of the root node are determined respectively, so as to generate logical code corresponding to the sub-database and the root metadata respectively.

[0015] In one embodiment, the metadata further includes multi-level nested nodes, and the step of generating logical code corresponding to the metadata using a code generation template associated with the metadata includes:

[0016] Based on the data combination extraction tags of the code generation template associated with the first metadata, determine the second metadata corresponding to the metadata identifier in the data combination extraction tags;

[0017] Traverse each node in the second metadata, and perform combination extraction processing on each node of the second metadata to obtain node metadata composed of each node;

[0018] The node metadata is used as the first metadata, and based on the first metadata, logical code corresponding to the first metadata is generated using a code generation template associated with the first metadata.

[0019] In one embodiment, the metadata further includes multi-level nested nodes, and the step of generating logical code corresponding to the metadata using a code generation template associated with the metadata includes:

[0020] Based on the data combination extraction tags of the code generation template associated with the first metadata, determine the second metadata corresponding to the metadata identifier in the data combination extraction tags;

[0021] Traverse each node in the second metadata, and perform combination extraction processing on each node of the second metadata to obtain node metadata composed of each node;

[0022] The node metadata is passed to the first metadata, and based on the first metadata, logical code corresponding to the first metadata is generated using the code generation template associated with the first metadata.

[0023] In one embodiment, determining the metadata associated with the code generation template according to the template mapping rules includes:

[0024] Based on the code generation template, create a new data source tag and determine the metadata identifier and metadata parsing template identifier in the new data source tag;

[0025] Determine the metadata corresponding to the metadata identifier, and determine the metadata parsing template corresponding to the metadata parsing template identifier;

[0026] The metadata is parsed using the metadata parsing template to obtain the parsed metadata;

[0027] The parsed metadata is used as metadata associated with the code generation template.

[0028] Secondly, embodiments of this application also provide a code generation apparatus, including:

[0029] The acquisition unit is used to retrieve the code generation template set according to the business requirements.

[0030] The determining unit is used to determine the metadata associated with the code generation template according to the template mapping rules;

[0031] The generation unit is used to generate logical code corresponding to the metadata based on the code generation template and using the metadata associated with the code generation template.

[0032] Thirdly, embodiments of this application also provide a computer device, including:

[0033] Central processing unit, memory, input / output interfaces;

[0034] The memory is either a short-term storage memory or a persistent storage memory;

[0035] The central processing unit is configured to communicate with the memory and execute instructions in the memory to perform any of the code generation methods described above.

[0036] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program thereon, wherein when the computer program is executed by a processor, it performs the code generation method described in any of the above-mentioned embodiments.

[0037] The fifth aspect of this application provides a computer program product having a computer program / instruction stored thereon, wherein the computer program / instruction, when executed by a processor, is used to implement the code generation method described in any of the preceding embodiments.

[0038] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:

[0039] The method involves obtaining a code generation template tailored to specific business requirements; determining the metadata associated with the code generation template based on template mapping rules; and generating corresponding logical code based on the metadata associated with the code generation template. By implementing the method of this application, when business requirements change, only the template or metadata needs to be updated, without rewriting the code. Business requirements in different scenarios can be dynamically generated using templates, significantly improving adaptability and versatility. Furthermore, once the template, mapping rules, and metadata are configured, the code generation process can be highly automated, effectively reducing repetitive work for developers and improving development efficiency. Attached Figure Description

[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0041] Figure 1 This is a schematic diagram of a code generation method provided in an embodiment of this application;

[0042] Figure 2 This is a schematic diagram of a code generation device provided in an embodiment of this application;

[0043] Figure 3 This is a schematic diagram of a computer device structure provided in an embodiment of this application. Detailed Implementation

[0044] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0045] As software development becomes increasingly complex, developers need to quickly generate code logic based on business requirements to meet development needs in different scenarios. To solve the problem of repetitive work and improve code development efficiency, code generation technology has gradually become an important tool in the development process.

[0046] In related technologies, developers typically manually write logic and concatenate it with data sources to generate business code. This string concatenation method is simple and intuitive, but as the business scales up, code maintenance and modification become complex and error-prone. Once requirements change, developers usually need to significantly modify the code, leading to high maintenance costs and low efficiency.

[0047] Based on this, the various embodiments of this application can decouple the structure of metadata from the generated code logic through flexible code generation template settings and template mapping rules, enabling the development process to quickly respond to changes in business requirements and automatically generate logic code.

[0048] The various embodiments of this application will now be described in further detail with reference to the accompanying drawings.

[0049] This application provides a code generation method, such as... Figure 1 As shown, the method includes steps S101-S103.

[0050] S101: Obtain the code generation template corresponding to the business requirements.

[0051] Code generation templates are predefined rules or formatted structures used to automatically generate code. Code generation templates can include: code snippet placeholders for marking parts that need to be dynamically populated, such as variables, function names, and parameters; different code structures for generating conditional statements or loops; and mapping rules for data binding, etc.

[0052] Code generation templates can be customized to meet various business needs. For example, templates can define the overall structure and layout of the system's front-end display page (e.g., header, sidebar, content area), and component interaction logic (e.g., form validation, button click events, dynamic data loading). Back-end templates can also be customized for core business logic, database interaction, and API processing. These templates can be flexibly configured to meet the needs of front-end, back-end, data management, test configuration, and specific scenarios.

[0053] S102: Determine the metadata associated with the code generation template based on the template mapping rules.

[0054] In one feasible embodiment, the template mapping rule is a mapping relationship between the data source of the code generation template and the type of metadata.

[0055] Template mapping rules are predefined, standardized, and encapsulated rules. These rules can include the following: the metadata type required by the template (e.g., Schema.Type), and the matching logic between the template and the metadata (e.g., field names, data structures). For example, assuming the template's data source field `Sources` is defined as `Table`, the mapping rule stipulates that when the `Schema.Type` in the metadata matches the value of the template's `Sources` field, the template's `Sources` will be mapped to one or more metadata fields with `Schema.Type` set to `Table`. Through this rule, the template can identify and find all matching schema data, thus serving as the data source for the code generation template.

[0056] It is important to understand that metadata schema refers to data that describes the structure, attributes, types, and other key information of certain business data, providing data support for subsequent code generation based on templates.

[0057] Metadata includes the following elements: ID (Identifier), Type, Props (Properties), and Children. The attribute settings for metadata may differ depending on the specific business data. For example, metadata for a database table may include the table name, field names, and data types; metadata for an API interface may include the interface path, parameter types, and return values; and metadata for the front-end display interface may include text content, UI control types, and UI control styles.

[0058] For example,

[0059]

[0060] Here, "id_001" is the unique identifier of this metadata, "form" indicates that the metadata belongs to a form, and "submiturl" is an attribute name in the props that specifies a Uniform Resource Locator (URL) to represent the target address when submitting data. "http: / / xxxx / add" is the value of this attribute, indicating that the data will be sent to this URL address when submitted, for form data submission or API requests. "children" refers to other elements contained in the current metadata element. In a hierarchical structure, children are the "child nodes" of the current metadata. "children" is usually a nested structure. For example, an input box component of type "input" with the identifier "id_002", its "text" attribute set to "input box content", and its width "width" specified as 80, can be nested as a child item within the parent container element if placed within "children": [].

[0061] In a feasible embodiment, the metadata associated with the code generation template is determined according to the template mapping rules, including: determining the metadata identifier and metadata parsing template identifier in the new data source tag based on the code generation template; determining the metadata corresponding to the metadata identifier, and determining the metadata parsing template corresponding to the metadata parsing template identifier; parsing the metadata using the metadata parsing template to obtain the parsed metadata; and using the parsed metadata as the metadata associated with the code generation template.

[0062] Suppose we have a template for front-end UI layout pages that includes configuration items for navigation links, describing how to navigate to another page, the navigation method, and the parameters that need to be passed. It's important to note that these configuration items are not directly usable route metadata; therefore, we need to construct new route definition data according to the route metadata format.

[0063] In this scenario, the metadata generated by the template can be used as a new data source for the template. See the example below for a specific creation method:

[0064] Example 1: {%assign newsource=parse|“mytempl”schema%}

[0065] The tag in Example 1 is generated by using the mytempl template and taking the schema as input data. After the template is parsed, new metadata is generated, which can then serve as a new data source for the template containing the tag.

[0066] In practical applications, developers only need to use the tag in the specified location. The metadata parsing template identifier in the tag will point to the corresponding metadata parsing template. Then, this template will parse the incoming metadata (determined based on the metadata identifier set in the tag), and the parsed metadata will become the new data source (newsource) of the template containing the tag.

[0067] Example 2: {%new "_route", schema%}

[0068] The tag in Example 2 indicates that the `_route` template is invoked, and the existing metadata schema is used as input to generate a new route definition metadata. Example 2 is suitable for situations where new business logic data needs to be built based on existing metadata, such as dynamically generating redirect links or route configurations.

[0069] In another feasible implementation, metadata generation does not solely rely on fixed data; placeholders can also be used in templates to concatenate dynamic content, thereby constructing flexible metadata. Below is an example of dynamically constructing metadata using placeholders:

[0070]

[0071] In this example, the value of `id` is not directly given, but is dynamically replaced using the template placeholder `{{schema.props.id}}`. During template parsing, `{{schema.props.id}}` will be replaced by the actual `schema.props.id` data value to generate the corresponding `id`. Similarly, the value of the `aa` attribute in the `props` section is dynamic, depending on the `schema.props.AA` data, and is replaced using the placeholder `{{schema.props.AA}}`. Ultimately, the value of `props.aa` will be filled according to the specific data in `schema.props.AA`. This embodiment builds flexible and configurable metadata by dynamically generating metadata and relying on actual runtime data to fill in placeholder values.

[0072] The above-described embodiments of this application automate and dynamize the metadata generation process through a template-driven approach, and greatly improve the flexibility and reusability of the template. During development, the template content can be adjusted according to actual needs without manually modifying the value of each field, thus improving development efficiency.

[0073] S103: Based on the code generation template, use the metadata associated with the code generation template to generate logical code corresponding to the metadata.

[0074] As described in the foregoing embodiments, a code generation template is a predefined format or structure, typically containing placeholders, logical controls, and formatting rules. In practical use, based on the template's logical structure and the specific business data content provided by the metadata, business logic code that conforms to the template's logic and business requirements can be automatically generated, such as code related to functions, classes, interfaces, and database operations.

[0075] In one embodiment, the metadata also includes a root node and multi-level nested child nodes. Based on the code generation template, logical code corresponding to the metadata is generated using the metadata associated with the code generation template. This includes: traversing each child node in the metadata associated with the code generation template based on the data splitting tags of the code generation template; splitting each child node to obtain at least one child metadata corresponding to each child node; obtaining at least one root metadata corresponding to the root node based on the root node; and determining the code generation template corresponding to the type of the child metadata and the code generation template corresponding to the type of the root node based on the type of the child metadata and the type of the root metadata, respectively, to generate logical code corresponding to the child metadata and the root metadata, respectively.

[0076] In real-world business scenarios, metadata is typically a multi-level, nested structure, usually following a tree structure. The root node is the top-level node, representing the overall business object or main structure. The root node is usually a business object (e.g., form, table, view), containing the definition or configuration of the entire object. Child nodes contain specific attributes, settings, or data, and each root node may have multiple child nodes. For example, the child nodes under the root node `table` object might include columns, indexes, etc., and these child nodes can further contain deeper levels of child nodes, forming a complex multi-level data structure. The data structure and type at each level may differ.

[0077] Because metadata is often complex in structure, and each business requirement only involves a portion of it, data splitting tags need to be set in the code generation template. This allows the template engine to traverse the metadata and identify which child nodes need to be split, thereby extracting the relevant business data corresponding to those child nodes. By splitting each child node and matching the corresponding code generation template based on the type of these child nodes, code that meets the business requirements can ultimately be generated.

[0078] For example, suppose there is a schema object in the metadata that contains multiple child nodes. The developer wants the generated code to split only a subset of these child nodes. Then the data splitting label can be set as follows:

[0079] {%for childin schema.children%}

[0080] {%disassembly child%}

[0081] {%endfor%}

[0082] In this example, `schema` is the root node, and `children` are its child nodes. The template iterates through all child nodes using `{%for child inschema.children%}`. Then, the `{%disassembly child%}` tag splits and processes each child node, ending the loop. Based on the different types of the split child metadata, corresponding code is matched to generate the template, thus generating the corresponding logic code. It should be noted that the above data splitting tags can be named or replaced as needed. For example, the `{%disassembly child%}` tag can be equivalently replaced by tags such as `{%source child%}`, depending on the template design and the data splitting logic. This application embodiment does not limit the specific code form of the data splitting tags.

[0083] In database code generation scenarios, metadata can be information related to the database definition, such as data related to objects like tables, views, and procedures. Fields and indexes within the database table definition can then be child nodes of this metadata. The code generation template can define how to generate SQL field and index definitions based on the table's child nodes (columns, indexes, etc.). In this case, the code generation template can be configured with data splitting tags based on the metadata hierarchy to traverse child nodes and generate code.

[0084] This application embodiment implements flexible splitting of multi-level nested structures of root nodes and child nodes in metadata for practical business applications. By setting data splitting tags in the code generation template, the template parsing engine can traverse each level of child nodes in the metadata and generate logic code by matching appropriate templates according to the type of child nodes. This application embodiment is suitable for handling complex data structures. Through this flexible splitting mechanism, it can adapt to different business needs and improve the automation level of code generation.

[0085] In one embodiment, the metadata also includes multi-level nested nodes. Based on the metadata, logical code corresponding to the metadata is generated using a code generation template associated with the metadata. This includes: extracting data combination tags based on the code generation template associated with the first metadata, determining the second metadata corresponding to the metadata identifier in the data combination extraction tags; traversing each node in the second metadata, performing combination extraction processing on each node of the second metadata to obtain node metadata composed of each node; using the node metadata as the first metadata, and generating logical code corresponding to the first metadata based on the first metadata using a code generation template associated with the first metadata.

[0086] First, data combination extraction tags are used in the code generation template to extract the second metadata required for the generated code corresponding to the first metadata. This tag can be understood as extracting and aggregating multiple sub-data or sub-nodes associated with the first metadata, thereby generating a new data source. Based on the metadata identifier in the data combination tag, the second metadata corresponding to that identifier can be found, and its nodes can be traversed. Each node may contain deeper nested data structures, so each node needs to be decomposed and extracted to obtain new node metadata composed of these nodes. This node metadata can be directly used as the first metadata, forming a new data source that can be used to generate the final logic code.

[0087] For example, suppose we are generating code for an order management system that has a business requirement: to dynamically generate logic code related to order details based on product information and other data.

[0088] For example, data combination labels can be set as follows:

[0089] {%iforder.props.status==“Awaiting Despatch”%}

[0090] {%for itemin order.props.items%}

[0091] {%subsource item, "productInfo"%} / / Extract "product information"

[0092] {%endfor%}

[0093] {%endif%}

[0094] By combining the above data tags, product information can be extracted in a combined manner to obtain new node metadata. The obtained node metadata is then used as the first metadata in the code generation template for subsequent generation of logic code corresponding to the first metadata.

[0095] In one embodiment, the metadata also includes multi-level nested nodes. Based on the metadata, logical code corresponding to the metadata is generated using a code generation template associated with the metadata. This includes: extracting data combinations based on the code generation template associated with the first metadata, determining the second metadata corresponding to the metadata identifier in the data combinations extraction tags; traversing each node in the second metadata, performing combination extraction processing on each node of the second metadata to obtain node metadata composed of each node; passing the node metadata to the first metadata, and generating logical code corresponding to the first metadata based on the first metadata using a code generation template associated with the first metadata.

[0096] This embodiment is largely similar to the previous embodiment, but the difference is that this embodiment passes the node metadata back to the first metadata, or it can also be understood as feeding back the generated child metadata to the parent data, and generating the final code based on the new parent data. It is suitable for situations where there is a dependency relationship between the root and child nodes.

[0097] For example, in front-end development, the main function of routing is to determine the corresponding page or component to display based on the user's access path. Faced with complex business requirements, page navigation logic may appear repeatedly on multiple pages. If each page has its own independent parsing code, this not only leads to repetitive work but also increases the risk of errors when updating routing information. To solve this problem, a centralized management strategy can be adopted, integrating the routing data of all business pages into a unified main route set, thereby achieving unified management and maintenance of routes.

[0098] To address the specific navigation requirements of each business page, we can first define unique metadata for each page. Then, by using data combination tags, we can effectively integrate these navigation metadata items scattered across different pages, extract them from their respective business page metadata, and finally pass them to the main route metadata. This allows us to generate corresponding route code for each business page using the main route metadata, facilitating maintenance during subsequent changes.

[0099] Specifically, assuming that the metadata for redirecting pages is defined in the pageRouteConfig object of a certain business page, the following data combination tags can be used to achieve automatic splitting and passing of metadata:

[0100] {%ifpageRouteConfig.props.open%}

[0101] {%subsource pageRouteConfig, "mainrouteid" %}

[0102] {%endif%}

[0103] The purpose of the above tag is to extract the metadata of the redirected page from pageRouteConfig when the open attribute of pageRouteConfig is true (i.e., when there is a page that needs to be redirected), and pass it to the main route metadata mainrouteid. In this way, the routing data of all redirected pages is centrally managed, which facilitates maintenance and updates, and also improves the maintainability and scalability of the code.

[0104] It is understandable that in a constantly changing business environment, traditional coding methods face a serious problem: when business requirements change, developers must modify a large amount of code to adapt to the new requirements. This is especially true when dealing with complex and multi-layered nested metadata structures, where every change in requirements can lead to tedious code modifications. However, this application's embodiment, by employing flexible code generation templates and template mapping rules, decouples the metadata structure from the generated code logic, enabling the development process to quickly respond to changes in business requirements. In this embodiment, templates are defined as static resources and associated with the metadata corresponding to the business data through mapping rules. Thus, once business requirements change, only the template or metadata needs to be updated, without rewriting a large amount of code. Template updates can be completed online without redeploying the application, greatly improving the system's flexibility and adaptability.

[0105] For example, the program originally needed to parse data from the database. As requirements change, the system may need to parse business-related data. In this case, developers only need to modify or add templates to adapt the code, so that the code can be updated adaptively without having to manually adjust the specific code in the program.

[0106] Furthermore, as business logic changes, the code generation template and metadata in this embodiment can be dynamically updated. Once the template and metadata configuration is complete, the code generation process can be highly automated, eliminating the tediousness and errors caused by manual code modification, without affecting the already released program. This not only saves development time but also enables the system to quickly adapt to new business requirements, allowing developers to focus more on business innovation rather than repetitive and inefficient code modification and maintenance, greatly improving development efficiency, system adaptability, and business responsiveness.

[0107] To implement the code generation method of this application embodiment, this application embodiment also provides a code generation apparatus, such as... Figure 2 As shown, the device includes:

[0108] Unit 201 is used to retrieve the code generation template set according to the business requirements.

[0109] The determining unit 202 is used to determine the metadata associated with the code generation template according to the template mapping rules;

[0110] The generation unit 203 is used to generate logical code corresponding to the metadata based on the code generation template and using the metadata associated with the code generation template.

[0111] In one embodiment, the template mapping rule is a mapping relationship between the data source of the code generation template and the type of the metadata.

[0112] In one embodiment, the metadata further includes a root node and multi-level nested child nodes, and the device further includes a processing unit; the processing unit is further configured to traverse each of the child nodes in the metadata associated with the code generation template based on the data splitting tags of the code generation template;

[0113] The processing unit is further configured to split each of the child nodes separately to obtain at least one child metadata corresponding to each child node;

[0114] The processing unit is further configured to obtain at least one root metadata corresponding to the root node based on the root node;

[0115] The determining unit 202 is further configured to determine, based on the type of the sub-data metadata and the type of the root metadata, a code generation template corresponding to the type of the sub-data metadata and a code generation template corresponding to the type of the root node, respectively, so as to generate logical code corresponding to the sub-data metadata and the root metadata.

[0116] In one embodiment, the metadata further includes multi-level nested nodes, and the determining unit 202 is further configured to determine the second metadata corresponding to the metadata identifier in the data combination extraction tag based on the data combination extraction tag of the code generation template associated with the first metadata;

[0117] The processing unit is further configured to traverse each of the nodes in the second metadata, perform combination extraction processing on each of the nodes in the second metadata, and obtain node metadata composed of each of the nodes.

[0118] The generation unit 203 is further configured to use the node metadata as the first metadata, and based on the first metadata, generate logical code corresponding to the first metadata using a code generation template associated with the first metadata.

[0119] In one embodiment, the metadata further includes multi-level nested nodes, and the determining unit 202 is further configured to determine the second metadata corresponding to the metadata identifier in the data combination extraction tag based on the data combination extraction tag of the code generation template associated with the first metadata;

[0120] The processing unit is further configured to traverse each of the nodes in the second metadata, perform combination extraction processing on each of the nodes in the second metadata, and obtain node metadata composed of each of the nodes.

[0121] The generation unit 203 is further configured to transmit the node metadata to the first metadata, and based on the first metadata, generate logical code corresponding to the first metadata using a code generation template associated with the first metadata.

[0122] In one embodiment, the determining unit 202 is further configured to create a new data source tag based on the code generation template, and determine the metadata identifier and metadata parsing template identifier in the new data source tag;

[0123] The determining unit 202 is further configured to determine the metadata corresponding to the metadata identifier and to determine the metadata parsing template corresponding to the metadata parsing template identifier;

[0124] The processing unit is further configured to parse the metadata using the metadata parsing template to obtain the parsed metadata;

[0125] The generation unit 203 is further configured to use the parsed metadata as metadata associated with the code generation template.

[0126] In practical applications, the processing unit can be implemented by the processor in the computer device in combination with the communication interface, and the acquisition unit 201, the determination unit 202, and the generation unit 203 can be implemented by the communication interface in the code generation device.

[0127] It should be noted that the code generation device provided in the above embodiments is only illustrated by the division of the above-described program modules. In practical applications, the above processing can be assigned to different program modules as needed, that is, the internal structure of the device can be divided into different program modules to complete all or part of the processing described above. In addition, the code generation device and the code generation method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.

[0128] Based on the hardware implementation of the above program modules, and in order to implement the code generation method provided in this application embodiment, this application embodiment also provides a computer device, such as... Figure 3 As shown, computer device 300 includes:

[0129] Central processing unit 301, memory 302, and input / output interface 303;

[0130] The memory 302 is a short-term storage memory or a persistent storage memory;

[0131] The central processing unit 301 is configured to communicate with the memory 302 and execute instructions in the memory 302 to perform any of the above-described code generation methods.

[0132] Of course, in practical applications, the various components in the computer device 300 are coupled together through a bus system 304. It is understood that the bus system 304 is used to realize communication between these components. In addition to a data bus, the bus system 304 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 3 The general designated all buses as Bus System 304.

[0133] The memory 302 in this embodiment is used to store various types of data to support the operation of the computer device 300. Examples of such data include any computer program used to operate on the computer device 300.

[0134] It is understood that when the processor in the computer device described above executes the computer program, it can also realize the functions of each unit in the corresponding device embodiments described above, which will not be repeated here. Exemplarily, the computer program can be divided into one or more modules / units, one or more modules / units are stored in memory and executed by the processor to complete the various embodiments of this application. One or more modules / units can be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the computer device. For example, the computer program can be divided into units in the aforementioned computer device, and each unit can implement the specific functions described in the corresponding computer device above.

[0135] Computer equipment can be desktop computers, laptops, handheld computers, and cloud servers, among other computing devices. Computer equipment may include, but is not limited to, processors and memory. Those skilled in the art will understand that processors and memory are merely examples of computer equipment and do not constitute a limitation on the computer equipment. It may include more or fewer components, or combinations of certain components, or different components. For example, computer equipment may also include input / output devices, network access devices, buses, etc.

[0136] A processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of a computer device, connecting all parts of the computer device through various interfaces and lines.

[0137] Memory can be used to store computer programs and / or modules. The processor performs various functions of the computer device by running or executing the computer programs and / or modules stored in the memory, and by accessing data stored in the memory. Memory can primarily include a program storage area and a data storage area. The program storage area can store the operating system, at least one application program required for a given function, etc.; the data storage area can store data created based on terminal usage, etc. Furthermore, memory can include high-speed random access memory, and can also include non-volatile memory, such as hard disks, RAM, plug-in hard disks, smart media cards (SMC), secure digital cards (SD), flash cards, at least one disk storage device, flash memory device, or other volatile solid-state storage devices.

[0138] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, performs any of the code generation methods described above.

[0139] This application also provides a computer program product storing a computer program / instruction, which, when executed by a processor, is used to implement the code generation method described in the first aspect or any specific implementation of the first aspect of this application.

[0140] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0141] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.

[0142] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0143] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0144] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

Claims

1. A code generation method, characterized in that, include: Get the code generation template that corresponds to the business requirements; Based on the template mapping rules, determine the metadata associated with the code generation template; Based on the code generation template, logical code corresponding to the metadata associated with the code generation template is generated. The step of determining the metadata associated with the code generation template according to the template mapping rules includes: Based on the code generation template, create a new data source tag and determine the metadata identifier and metadata parsing template identifier in the new data source tag; Determine the metadata corresponding to the metadata identifier, and determine the metadata parsing template corresponding to the metadata parsing template identifier; The metadata is parsed using the metadata parsing template to obtain the parsed metadata; The parsed metadata is used as metadata associated with the code generation template; When the metadata also includes a root node and multi-level nested child nodes, the step of generating logical code corresponding to the metadata based on the code generation template and using the metadata associated with the code generation template includes: Based on the data splitting tags of the code generation template, traverse each of the child nodes in the metadata associated with the code generation template; Each of the child nodes is split and processed to obtain at least one sub-data element corresponding to each child node; Based on the root node, at least one root metadata corresponding to the root node is obtained; Based on the type of the sub-database and the type of the root metadata, code generation templates corresponding to the type of the sub-database and the type of the root node are determined respectively, so as to generate logical code corresponding to the sub-database and the root metadata respectively.

2. The code generation method according to claim 1, characterized in that, The template mapping rule is the mapping relationship between the data source of the code generation template and the type of the metadata.

3. The code generation method according to claim 1, characterized in that, The metadata also includes multi-level nested nodes. Based on the metadata, logical code corresponding to the metadata is generated using a code generation template associated with the metadata, including: Based on the data combination extraction tags of the code generation template associated with the first metadata, determine the second metadata corresponding to the metadata identifier in the data combination extraction tags; Traverse each node in the second metadata, and perform combination extraction processing on each node of the second metadata to obtain node metadata composed of each node; The node metadata is used as the first metadata, and based on the first metadata, logical code corresponding to the first metadata is generated using a code generation template associated with the first metadata.

4. The code generation method according to claim 1, characterized in that, The metadata also includes multi-level nested nodes. Based on the metadata, logical code corresponding to the metadata is generated using a code generation template associated with the metadata, including: Based on the data combination extraction tags of the code generation template associated with the first metadata, determine the second metadata corresponding to the metadata identifier in the data combination extraction tags; Traverse each node in the second metadata, and perform combination extraction processing on each node of the second metadata to obtain node metadata composed of each node; The node metadata is passed to the first metadata, and based on the first metadata, logical code corresponding to the first metadata is generated using the code generation template associated with the first metadata.

5. A code generation device, characterized in that, include: The acquisition unit is used to retrieve the code generation template set according to the business requirements. The determining unit is used to determine the metadata associated with the code generation template according to the template mapping rules; A generation unit is used to generate logical code corresponding to the metadata based on the code generation template and using the metadata associated with the code generation template. The determining unit is specifically used to: based on the code generation template, create a new data source tag, and determine the metadata identifier and metadata parsing template identifier in the new data source tag; Determine the metadata corresponding to the metadata identifier, and determine the metadata parsing template corresponding to the metadata parsing template identifier; The metadata is parsed using the metadata parsing template to obtain the parsed metadata; The parsed metadata is used as metadata associated with the code generation template; When the metadata also includes a root node and multi-level nested child nodes, the generation unit is specifically used to: based on the data splitting tags of the code generation template, traverse each of the child nodes in the metadata associated with the code generation template; and perform splitting processing on each of the child nodes to obtain at least one sub-metadata corresponding to each child node; Based on the root node, at least one root metadata corresponding to the root node is obtained; based on the type of the sub-metadata and the type of the root metadata, code generation templates corresponding to the type of the sub-metadata and the type of the root node are determined respectively, so as to generate logical code corresponding to the sub-metadata and the root metadata respectively.

6. A computer device, characterized in that, include: Central processing unit, memory, and input / output interfaces; The central processing unit is configured to communicate with the memory and execute instructions in the memory to perform the code generation method according to any one of claims 1 to 4.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it performs the code generation method as described in any one of claims 1 to 4.

8. A computer program product having a computer program / instructions stored thereon, characterized in that, When the computer program / instructions are executed by the processor, they are used to implement the code generation method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Code file generation method and device, computer device, and storage medium

    CN109032662A

  • Simulation rule code automatic generation method and device

    CN116974568A