Code generation method and device, equipment and storage medium
By obtaining and mapping code generation templates and metadata, and generating logical code, it solves the complex problems of code maintenance and modification, realizes the automation and flexibility of the code generation process, and improves development efficiency and adaptability.
Patent Information
- Application Number
- CN202411887206.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2044-12-18
AI Technical Summary
In the prior art, the maintenance and modification of codes are complex and error-prone, resulting in high maintenance costs and low efficiency, especially when business needs change, the code needs to be modified significantly.
Generate templates by obtaining code for business needs and determining the metadata associated with the template according to template mapping rules, and generate logical codes corresponding to the metadata. This method makes the code generation process reusable and standardized, reduces maintenance costs and enhances scalability.
It realizes a high degree of automation of the code generation process, reduces the repetitive labor of developers, improves development efficiency, can quickly respond to changes in business needs, and reduces maintenance costs.
Smart Images

Figure CN119847499A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to code generation methods, devices, equipment and storage media. Background Art
[0002] As the complexity of software development continues to increase, developers need to quickly generate code logic based on business needs to meet development requirements in different scenarios. In order to solve the problem of duplication of work and improve code development efficiency, code generation technology has gradually become an important tool in the development process.
[0003] In the related art, developers usually manually write logic and generate business codes based on data source splicing. This string splicing method is simple and intuitive, but as the business scale expands, code maintenance and modification become complicated and error-prone. Once the requirements change, developers usually need to modify the code again, resulting in high maintenance costs and low efficiency. Summary of the invention
[0004] Based on the above problems, the embodiments of the present application provide a code generation method, apparatus, device and storage medium, the purpose of which is to achieve reusability and standardization of the code generation process, reduce maintenance costs and enhance scalability.
[0005] In a first aspect, an embodiment of the present application provides a code generation method, comprising:
[0006] Get the code generation template that is set up according to business requirements;
[0007] Determining metadata associated with the code generation template according to a template mapping rule;
[0008] Based on the code generation template, the metadata associated with the code generation template is used to generate logic code corresponding to the metadata.
[0009] In one embodiment, the template mapping rule is a mapping relationship between a data source of the code generation template and a type of the metadata.
[0010] In one embodiment, the metadata further includes a root node and multi-level nested child nodes, and the step of generating logic code corresponding to the metadata based on the code generation template and using the metadata associated with the code generation template includes:
[0011] Based on the data splitting tag of the code generation template, traverse each of the sub-nodes in the metadata associated with the code generation template;
[0012] Splitting each of the sub-nodes respectively to obtain at least one sub-metadata corresponding to each of the sub-nodes;
[0013] According to the root node, obtaining at least one root metadata corresponding to the root node;
[0014] According to the type of the sub-metadata and the type of the root metadata, a code generation template corresponding to the type of the sub-metadata and a code generation template corresponding to the type of the root node are determined respectively to generate logic codes corresponding to the sub-metadata and the root metadata respectively.
[0015] In one embodiment, the metadata further includes multi-level nested nodes, and the step of generating logic code corresponding to the metadata based on the metadata and using a code generation template associated with the metadata includes:
[0016] Based on the data combination extraction tag of the code generation template associated with the first metadata, determining second metadata corresponding to the metadata identifier in the data combination extraction tag;
[0017] Traversing each of the nodes in the second metadata, performing combination extraction processing on each of the nodes in the second metadata, and obtaining node metadata composed of each of the nodes;
[0018] The node metadata is used as the first metadata, and based on the first metadata, a code generation template associated with the first metadata is used to generate logic code corresponding to the first metadata.
[0019] In one embodiment, the metadata further includes multi-level nested nodes, and the step of generating logic code corresponding to the metadata based on the metadata and using a code generation template associated with the metadata includes:
[0020] Based on the data combination extraction tag of the code generation template associated with the first metadata, determining second metadata corresponding to the metadata identifier in the data combination extraction tag;
[0021] Traversing each of the nodes in the second metadata, performing combination extraction processing on each of the nodes in the second metadata, and obtaining node metadata composed of each of the nodes;
[0022] The node metadata is transferred to the first metadata, and based on the first metadata, a logic code corresponding to the first metadata is generated by using a code generation template associated with the first metadata.
[0023] In one embodiment, determining metadata associated with the code generation template according to a template mapping rule includes:
[0024] Based on the creation of a new data source tag of the code generation template, determining a metadata identifier and a metadata parsing template identifier in the creation of the new data source tag;
[0025] Determining metadata corresponding to the metadata identifier, and determining a metadata parsing template corresponding to the metadata parsing template identifier;
[0026] Parsing the metadata using the metadata parsing template to obtain parsed metadata;
[0027] The parsed metadata is used as metadata associated with the code generation template.
[0028] In a second aspect, the embodiment of the present application further provides a code generation device, including:
[0029] An acquisition unit, used to acquire a code generation template set corresponding to business requirements;
[0030] A determination unit, configured to determine metadata associated with the code generation template according to a template mapping rule;
[0031] A generating unit is used to generate logic code corresponding to the metadata based on the code generation template and using the metadata associated with the code generation template.
[0032] In a third aspect, an embodiment of the present application further provides a computer device, including:
[0033] CPU, memory, input and output interfaces;
[0034] The memory is a short-term storage memory or a persistent storage memory;
[0035] The central processing unit is configured to communicate with the memory and execute instruction operations in the memory to perform any one of the above-mentioned code generation methods.
[0036] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, any one of the above-mentioned code generation methods is executed.
[0037] A fifth aspect of an embodiment of the present 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 any of the code generation methods described above.
[0038] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0039] Obtain a code generation template that is set up corresponding to the business needs; determine the metadata associated with the code generation template according to the template mapping rules; based on the code generation template, use the metadata associated with the code generation template to generate logic code corresponding to the metadata. By implementing the method of the embodiment of the present application, when business needs change, it is only necessary to update the template or metadata without rewriting the code. Business needs in different scenarios can dynamically generate corresponding codes through templates, thereby significantly improving adaptability and versatility. In addition, after the configuration of templates, mapping rules and metadata is completed, the code generation process can be highly automated, effectively reducing the repetitive work of developers and improving development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0041] Figure 1 A schematic diagram of a code generation method flow provided in an embodiment of the present application;
[0042] Figure 2 A schematic diagram of the structure of a code generation device provided in an embodiment of the present application;
[0043] Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0045] As the complexity of software development continues to increase, developers need to quickly generate code logic based on business needs to meet development requirements in different scenarios. In order to solve the problem of duplication of work and improve code development efficiency, code generation technology has gradually become an important tool in the development process.
[0046] In the related art, developers usually manually write logic and generate business codes based on data source splicing. This string splicing method is simple and intuitive, but as the business scale expands, code maintenance and modification become complicated and error-prone. Once the requirements change, developers usually need to modify the code again, resulting in high maintenance costs and low efficiency.
[0047] Based on this, in various embodiments of the present application, through flexible code generation template settings and template mapping rules, the metadata structure can be decoupled from the generated code logic, so that the development process can quickly respond to changes in business needs and automatically generate logical code.
[0048] The various embodiments of the present application are described in further detail below in conjunction with the accompanying drawings.
[0049] The present application embodiment provides a code generation method, such as Figure 1 As shown, the method includes steps S101-S103.
[0050] S101: Obtain a code generation template configured to meet business requirements.
[0051] Code generation templates are predefined rules or formatting structures used to automatically generate code. Code generation templates can include: code snippet placeholders for marking parts that need to be dynamically filled, such as variables, function names, parameters, etc., different code structures containing conditional judgments or loops, and mapping rules for data binding, etc.
[0052] Code generation templates can be set according to different business needs, such as templates that define the overall structure and layout of the system front-end display page (such as header, sidebar, content area, etc.), component interaction logic (such as form validation, button click events, dynamic data loading) templates; core business logic templates for the system back-end, database interaction templates, interface processing templates, etc. Code generation templates can be flexibly set according to the needs of the front-end, back-end, data management, test configuration, and specific scenarios.
[0053] S102: Determine metadata associated with the code generation template according to the template mapping rule.
[0054] In a feasible embodiment, the template mapping rule is a mapping relationship between a data source of a code generation template and a type of metadata.
[0055] Template mapping rules are predefined, standardized and encapsulated rules. Template mapping rules can include the following: the metadata type required by the template (such as Schema.Type), the matching logic between the template and the metadata (such as field name, data structure), etc. For example, assuming that the data source field Sources of the template is defined as Table, the mapping rule stipulates that when the Schema.Type in the metadata is the same as the value of the Sources field of the template, the Sources of the template is mapped to one or more metadata with Schema.Type of Table. Through this rule, the template can determine and find all qualified Schema data, so as to serve as the data source of 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, Type, Props, Properties, and Children. The attribute settings of metadata may be different for different business data. For example, the metadata of a database table may include table name, field name, data type, etc.; the metadata of an API interface may include interface path, parameter type, return value, etc.; the metadata of a front-end display interface may include text content, interface control type, interface control style, etc.
[0058] For example,
[0059]
[0060] Among them, "id_001" is the unique identifier of the metadata, "form" indicates that the type of metadata is a form, and "submiturl" is a property name in props, which is used to specify a uniform resource locator (URL, UniformResource Locator), which indicates the target address when submitting data. "http: / / xxxx / add" is the value of this property, which means that the data will be sent to this URL address when submitted, which is used for form data submission or API request. "Children" refers to other elements contained in the current metadata element. In the 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" has an identifier of "id_002", the "text" attribute is set to "input box content", and the width of the input box "width" is specified as 80. This input box component is set in "children": [], and can be nested as a child in the parent container element.
[0061] In a feasible embodiment, metadata associated with a code generation template is determined according to a template mapping rule, including: determining a metadata identifier and a metadata parsing template identifier in a create new data source tag based on the code generation template; determining metadata corresponding to the metadata identifier, and determining a metadata parsing template corresponding to the metadata parsing template identifier; parsing the metadata using the metadata parsing template to obtain parsed metadata; and using the parsed metadata as metadata associated with the code generation template.
[0062] Suppose there is a template for the front-end interface layout page, which contains configuration items about jump links, describing how to jump to another page, the jump method, and the parameters to be passed, etc. It should be noted that these configuration items are not directly available routing metadata, so a new routing definition data needs to be constructed according to the format of routing metadata.
[0063] In this case, the metadata generated by the template can be used as the new data source of the template. For the specific creation method, refer to the following example:
[0064] Example 1: {% assign newsource = parse|"mytempl", schema %}
[0065] The tag in Example 1 is created by using the mytempl template and taking the schema as input data. After the template is parsed, new metadata is generated. The generated new metadata can be used as a new data source for the template where the tag is located.
[0066] In actual applications, developers only need to use the tag at the specified location. The metadata parsing template identifier in the tag will point to the corresponding metadata parsing template, and then the template will perform parsing based on the incoming metadata (determined based on the metadata identifier set in the tag). The parsed metadata will be used as the new data source (newsource) of the template where the tag is located.
[0067] Example 2: {% new "_route", schema %}
[0068] The tag in Example 2 indicates that the _route template is called and the existing metadata schema is used as input to generate a new route definition metadata. Example 2 is suitable for building new business logic data based on existing metadata, such as dynamically generating jump links and route configurations.
[0069] In another feasible embodiment, the generation of metadata does not only rely on fixed data, but also placeholders can be used in the template to splice dynamic content to construct flexible metadata. The following is an example of dynamically constructing metadata through placeholders:
[0070]
[0071] In this example, the value of id is not given directly, but is dynamically replaced by the template placeholder {{schema.props.id}}. When the template is parsed, {{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 part is dynamic and depends on the schema.props.AA data, and is replaced by the placeholder {{schema.props.AA}}. Finally, the value of props.aa will be filled in according to the specific data of schema.props.AA. This embodiment builds flexible and configurable metadata by dynamically generating metadata and filling in placeholder values based on actual runtime data.
[0072] The above-mentioned embodiments of the present application make the metadata generation process automated and dynamic through a template-driven approach, and greatly improve the flexibility and reusability of the template. During the development process, the template content can be adjusted according to actual needs without manually modifying the value of each field, thereby improving development efficiency.
[0073] S103: Based on the code generation template, using metadata associated with the code generation template, generate logic code corresponding to the metadata.
[0074] As can be seen from the above embodiments, a code generation template is a predefined format or structure, which usually contains placeholders, logic controls and formatting rules. In actual use, business logic code that meets the template logic and business requirements can be automatically generated based on the logical structure of the template and the specific business data content provided by the metadata, such as functions, classes, interfaces, database operations and other related codes.
[0075] In one embodiment, the metadata also includes a root node and multi-level nested child nodes. Based on a code generation template, the metadata associated with the code generation template is used to generate logic code corresponding to the metadata, including: based on the data splitting tag of the code generation template, traversing each child node in the metadata associated with the code generation template; splitting each child node separately to obtain at least one child metadata corresponding to each child node; according to the root node, obtaining at least one root metadata corresponding to the root node; according to the type of the child metadata and the type of the root metadata, 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 respectively, so as to generate logic codes corresponding to the child metadata and the root metadata respectively.
[0076] In actual business scenarios, metadata is usually a multi-level, nested structure. The composition of metadata usually follows 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 (for example, form, table, view, etc.), which contains the definition or configuration of the entire object. The child nodes contain specific properties, settings, or data, and each root node may have multiple child nodes. For example, the child nodes under the root node table object may include fields (columns), indexes (indexes), etc., and the child nodes may further contain deeper child nodes, forming a complex multi-level data structure. The data structure and type of each layer may be different.
[0077] Since metadata is usually complex in structure and each business requirement only involves a part of it, it is necessary to set data splitting tags in the code generation template to traverse the metadata and help the template engine identify which subnodes need to be split, so as to extract the business data corresponding to the relevant subnodes. By splitting each subnode and matching the corresponding code generation template according to the type of these subnodes, code that meets business requirements can be generated in the end.
[0078] For example, suppose there is a schema object in the metadata, which contains multiple child nodes. The developer wants to generate code to split only some of the child nodes. Then the data splitting tag 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 is its child nodes. Through {% for child inschema.children %}, the template will traverse all child nodes. Then, the {% disassembly child %} tag will split and process each child node, and then end the loop. According to the different types of split child metadata, the corresponding code generation template is matched to generate the corresponding logic code. It should be pointed out that the above-mentioned 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 design of the template and the logic of data splitting. The embodiment of the present application does not limit the specific code form of the data splitting tag.
[0083] In the scenario of database code generation, metadata can be information related to database definitions, such as data related to objects such as tables, views, and procedures. The fields (columns), indexes, and other information in the database table definition can be used as child nodes of metadata. The code generation template can define how to generate SQL field definitions, index definitions, etc. based on the child nodes (columns, indexes, etc.) of the table. In this case, you can set data splitting tags in the code generation template to traverse the child nodes and generate code based on the hierarchical structure of the metadata.
[0084] The embodiment of the present application realizes the flexible splitting processing of the multi-level nested structure of the root node and the child node in the metadata in the actual business application. By setting the data splitting label in the code generation template, the template parsing engine can traverse the sub-nodes of each layer of the metadata and match the appropriate template to generate logic code according to the type of the child node. The embodiment of the present application is suitable for processing complex data structures. Through this flexible splitting mechanism, it can adapt to different business needs and improve the automation of code generation.
[0085] In one embodiment, the metadata also includes multi-level nested nodes. Based on the metadata, a code generation template associated with the metadata is used to generate logic code corresponding to the metadata, including: based on a data combination extraction tag of the code generation template associated with the first metadata, determining second metadata corresponding to the metadata identifier in the data combination extraction tag; traversing each node in the second metadata, performing combination extraction processing on each node of the second metadata, and obtaining node metadata composed of each node; using the node metadata as the first metadata, and based on the first metadata, using the code generation template associated with the first metadata, generating logic code corresponding to the first metadata.
[0086] First, use the data combination extraction tag in the code generation template to extract the second metadata required for the code generated corresponding to the first metadata. The role of 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. According to the metadata identifier in the data combination tag, the second metadata corresponding to the metadata identifier can be found, and each node therein can be traversed. Each node may contain a deeper nested data structure, so each node needs to be disassembled and extracted to obtain new node metadata composed of each node. These node metadata can be directly used as the first metadata to form a new data source that can be used to generate code and generate the final logical code.
[0087] For example, suppose we are generating code for an order management system that has a business requirement: dynamically generate logic code related to order details based on product information, etc.
[0088] Exemplarily, the data combination tag 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] Through the above data combination tags, the commodity information can be combined and extracted to obtain new node metadata, and the obtained node metadata is used as the first metadata in the code generation template to be used 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, a code generation template associated with the metadata is used to generate logic code corresponding to the metadata, including: based on a data combination extraction tag of the code generation template associated with the first metadata, determining the second metadata corresponding to the metadata identifier in the data combination extraction tag; traversing each node in the second metadata, performing combination extraction processing on each node of the second metadata, and obtaining node metadata composed of each node; passing the node metadata to the first metadata, and based on the first metadata, generating a logic code corresponding to the first metadata using the code generation template associated with the first metadata.
[0096] This embodiment is roughly 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 the generated child metadata back 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 needs, page jump logic may be repeated in multiple pages. If each page is independently written with parsing code, this will not only lead to duplication of work, but also increase the risk of errors when updating routing information. In order to solve this problem, a centralized management strategy can be adopted to integrate the routing data of all business pages into a unified main routing set, thereby realizing unified management and maintenance of routing.
[0098] In order to meet the specific jump requirements of each business page, you can first define specific metadata for each page. Then, by using data combination tags, you can effectively integrate the jump metadata scattered on different pages, extract them from the metadata of each business page, and finally pass them to the main routing metadata. In this way, you can generate the corresponding routing code for each business page through the main routing metadata, which is also convenient for maintenance when changes are made later.
[0099] Specifically, assuming that the metadata of the jump page is defined in the pageRouteConfig object of a business page, the following data combination tags can be used to achieve automatic splitting and transmission of metadata:
[0100] {%ifpageRouteConfig.props.open%}
[0101] {%subsource pageRouteConfig, "mainrouteid" %}
[0102] {% endif %}
[0103] The function of the above tag is: when the open attribute of pageRouteConfig is true (that is, when there is a page that needs to be redirected), the redirect page metadata in pageRouteConfig is split out and passed to the main route metadata mainrouteid. In this way, the route data of all redirect pages are centrally managed, which is also convenient for maintenance and updating, and also improves the maintainability and scalability of the code.
[0104] It is understandable that in an ever-changing business environment, the traditional way of writing code faces a serious problem: when business requirements change, developers must modify a large amount of code to adapt to the new requirements. Especially when faced with complex and multi-layered nested metadata structures, each change in requirements may lead to cumbersome code modification work. However, the embodiment of the present application can decouple the structure of metadata from the generated code logic by adopting flexible code generation templates and template mapping rules, so that the development process can respond quickly to changes in business requirements. In the embodiment of the present application, the template is defined as a static resource and is associated with the metadata corresponding to the business data through mapping rules. In this way, once the business requirements change, only the template or metadata needs to be updated without rewriting a large amount of code. The update of the template can be completed online without republishing the application, thereby greatly improving the flexibility and adaptability of the system.
[0105] For example, the original program needs to parse data in the database. As the demand changes, the system may need to parse business-related data. At this time, the developer only needs to modify or adaptively add templates, so that the code can be adaptively updated, without having to manually adjust the specific code in the program.
[0106] Furthermore, as the business logic changes, the code generation template and metadata of the embodiment of the present application can be dynamically updated. Once the configuration of the template and metadata is completed, the code generation process can be highly automated, eliminating the tediousness and errors caused by manual code modification without affecting the published programs. This not only saves development time, but also enables the system to quickly adapt to new business needs, 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] In order to implement the code generation method of the embodiment of the present application, the embodiment of the present application also provides a code generation device, such as Figure 2 As shown, the device comprises:
[0108] An acquisition unit 201 is used to acquire a code generation template set corresponding to a business requirement;
[0109] A determination unit 202, configured to determine metadata associated with the code generation template according to a template mapping rule;
[0110] The generating unit 203 is configured to generate logic code corresponding to the metadata based on the code generating template and using the metadata associated with the code generating template.
[0111] In one embodiment, the template mapping rule is a mapping relationship between a data source of the code generation template and a 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 label of the code generation template;
[0113] The processing unit is further used to split each of the sub-nodes to obtain at least one sub-metadata corresponding to each of the sub-nodes;
[0114] The processing unit is further configured to obtain, according to the root node, at least one root metadata corresponding to the root node;
[0115] The determination unit 202 is also used to determine, according to the type of the sub-metadata and the type of the root metadata, a code generation template corresponding to the type of the sub-metadata and a code generation template corresponding to the type of the root node, so as to generate logic codes corresponding to the sub-metadata and the root metadata, respectively.
[0116] In one embodiment, the metadata further includes multi-level nested nodes, and the determining unit 202 is further configured to determine, based on the data combination extraction tag of the code generation template associated with the first metadata, the second metadata corresponding to the metadata identifier in the data combination extraction tag;
[0117] The processing unit is further used 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 generating unit 203 is further configured to use the node metadata as the first metadata, and based on the first metadata, generate logic 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, based on the data combination extraction tag of the code generation template associated with the first metadata, the second metadata corresponding to the metadata identifier in the data combination extraction tag;
[0120] The processing unit is further used 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 generating unit 203 is further configured to transfer the node metadata to the first metadata, and based on the first metadata, generate logic code corresponding to the first metadata by using a code generation template associated with the first metadata.
[0122] In one embodiment, the determining unit 202 is further configured to determine a metadata identifier and a metadata parsing template identifier in the create new data source tag based on the create new data source tag of the code generation template;
[0123] The determining unit 202 is further configured to determine metadata corresponding to the metadata identifier and determine a metadata parsing template corresponding to the metadata parsing template identifier;
[0124] The processing unit is further used to parse the metadata using the metadata parsing template to obtain parsed metadata;
[0125] The generating unit 203 is further configured to use the parsed metadata as metadata associated with the code generation template.
[0126] In actual application, the processing unit can be implemented by a processor in a computer device in combination with a communication interface, and the acquisition unit 201, the determination unit 202, and the generation unit 203 can be implemented by a communication interface in a code generation device.
[0127] It should be noted that: the above embodiment provides a code generation device, and only uses the division of the above program modules as an example to illustrate when performing code generation. In actual applications, the above processing can be assigned to different program modules as needed, that is, the internal structure of the device is divided into different program modules to complete all or part of the above-described processing. In addition, the code generation device provided in the above embodiment and the code generation method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0128] Based on the hardware implementation of the above program modules, and in order to implement a code generation method provided in an embodiment of the present application, an embodiment of the present application further provides a computer device, such as Figure 3 As shown, the computer device 300 includes:
[0129] CPU 301, memory 302 and input / output interface 303;
[0130] The memory 302 is a temporary storage memory or a permanent 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 one of the above code generation methods.
[0132] Of course, in actual application, the various components in the computer device 300 are coupled together through the bus system 304. It can be understood that the bus system 304 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 304 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, Figure 3 Various buses are labeled as bus system 304 .
[0133] The memory 302 in the embodiment of the present application 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 understandable that when the processor in the computer device described above executes the computer program, it can also implement the functions of the various units in the above-mentioned corresponding device embodiments, 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 the memory, and executed by the processor to complete the various embodiments of the present application. One or more modules / units can be a series of computer program instruction segments that can perform specific functions, and the instruction segments are used to describe the execution process of the computer program in the computer device. For example, the computer program can be divided into the various units in the above-mentioned computer device, and each unit can implement the specific functions described in the above-mentioned corresponding computer device.
[0135] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, and a cloud server. The computer device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the processor and the memory are merely examples of computer devices and do not constitute a limitation on the computer device. The computer device may include more or fewer components, or a combination of certain components, or different components. For example, the computer device may also include input and output devices, network access devices, buses, etc.
[0136] The processor can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) 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, etc. The processor is the control center of the computer device, and uses various interfaces and lines to connect various parts of the entire computer device.
[0137] The memory can be used to store computer programs and / or modules. The processor implements various functions of the computer device by running or executing the computer programs and / or modules stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created according to the use of the terminal, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SMC, Smart Media Card), a secure digital (SD, Secure Digital) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0138] An embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, any one of the above-mentioned code generation methods is executed.
[0139] An embodiment of the present application also provides a computer program product having a computer program / instruction stored thereon. When the computer program / instruction is executed by a processor, it is used to implement the code generation method described in the first aspect of the embodiment of the present application or any specific implementation method of the first aspect.
[0140] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0141] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0142] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0143] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0144] If the integrated unit is implemented in the form of 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 the present application is essentially 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, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
Claims
1. A code generation method, characterized in that: include: Get the code generation template that is set up according to business requirements; Determining metadata associated with the code generation template according to a template mapping rule; Based on the code generation template, and using metadata associated with the code generation template, logic code corresponding to the metadata is generated.
2. The code generation method according to claim 1, characterized in that: The template mapping rule is a 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 a root node and multi-level nested child nodes. The step of generating logic 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 tag of the code generation template, traverse each of the sub-nodes in the metadata associated with the code generation template; Splitting each of the sub-nodes respectively to obtain at least one sub-metadata corresponding to each of the sub-nodes; According to the root node, obtaining at least one root metadata corresponding to the root node; According to the type of the sub-metadata and the type of the root metadata, a code generation template corresponding to the type of the sub-metadata and a code generation template corresponding to the type of the root node are determined respectively to generate logic codes corresponding to the sub-metadata and the root metadata respectively.
4. The code generation method according to claim 1, characterized in that: The metadata also includes multi-level nested nodes. Based on the metadata, using a code generation template associated with the metadata, generating logic code corresponding to the metadata includes: Based on the data combination extraction tag of the code generation template associated with the first metadata, determining second metadata corresponding to the metadata identifier in the data combination extraction tag; Traversing each of the nodes in the second metadata, performing combination extraction processing on each of the nodes in the second metadata, and obtaining node metadata composed of each of the nodes; The node metadata is used as the first metadata, and based on the first metadata, a code generation template associated with the first metadata is used to generate logic code corresponding to the first metadata.
5. The code generation method according to claim 4, characterized in that: The metadata also includes multi-level nested nodes. Based on the metadata, using a code generation template associated with the metadata, generating logic code corresponding to the metadata includes: Based on the data combination extraction tag of the code generation template associated with the first metadata, determining second metadata corresponding to the metadata identifier in the data combination extraction tag; Traversing each of the nodes in the second metadata, performing combination extraction processing on each of the nodes in the second metadata, and obtaining node metadata composed of each of the nodes; The node metadata is transferred to the first metadata, and based on the first metadata, a logic code corresponding to the first metadata is generated by using a code generation template associated with the first metadata.
6. The code generation method according to claim 1, characterized in that: The step of determining metadata associated with the code generation template according to the template mapping rule includes: Based on the creation of a new data source tag of the code generation template, determining a metadata identifier and a metadata parsing template identifier in the creation of the new data source tag; Determining metadata corresponding to the metadata identifier, and determining a metadata parsing template corresponding to the metadata parsing template identifier; Parsing the metadata using the metadata parsing template to obtain parsed metadata; The parsed metadata is used as metadata associated with the code generation template.
7. A code generating device, characterized in that: include: An acquisition unit, used to acquire a code generation template set corresponding to business requirements; A determination unit, configured to determine metadata associated with the code generation template according to a template mapping rule; A generating unit is used to generate logic code corresponding to the metadata based on the code generation template and using metadata associated with the code generation template.
8. A computer device, characterized in that: include: CPU, memory and input / output interface; The memory is a transient storage memory or a persistent storage memory; The central processing unit is configured to communicate with the memory and execute instruction operations in the memory to perform the code generation method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the code generation method according to any one of claims 1 to 6 is performed.
10. A computer program product having a computer program / instructions stored thereon, characterized in that: When the computer program / instructions are executed by a processor, they are used to implement the code generation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Code file generation method and device, computer device, and storage medium
CN109032662A
Code generation method and device, equipment, medium and program
CN115951871A
Simulation rule code automatic generation method and device
CN116974568A
Code generation method, code generation display method, electronic equipment and storage medium
CN118466915A