Code generation method and device, equipment and storage medium

By using a code generator to parse the target data table and look up mapping relationships, functional code for multi-forms is generated, solving the problem that existing technologies cannot generate multi-forms and improving software development efficiency.

CN115291887BActive Publication Date: 2025-10-21SHENZHEN FENGMANG INFORMATION TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202210972776.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-15
Publication Date
2025-10-21
Estimated Expiration
2042-08-15

AI Technical Summary

Technical Problem

Existing code generators are unable to generate functional code with multiple forms, resulting in wasted software development time.

Method used

The code generator parses the target data table in the preset database to obtain target annotation information, and then searches for the corresponding target code block in the preset mapping relationship based on the annotation information. The target code block is then copied to the code generation file to generate the corresponding code.

Benefits of technology

The code for generating multi-form functionality was implemented, which improved software development efficiency, reduced workload, and increased work efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115291887B_ABST
    Figure CN115291887B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of computers and discloses a code generation method, device and equipment and a storage medium, the method comprising the following steps: when a code generation instruction is received, corresponding target data tables are found from a preset database; the target data tables are parsed by a code generator to obtain target annotation information; corresponding target code blocks are found in a preset mapping relationship according to the target annotation information; and the target code blocks are copied to a code generation file, so that the code generator generates corresponding codes according to the code generation file. Since the target data tables found from the database are parsed by the code generator to obtain the target annotation information, and the target code blocks obtained through the target annotation information are copied to the code generation file to generate corresponding codes, the problem that the existing code generator cannot generate functional codes with multiple forms is solved, and the software development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a code generation method, apparatus, device and storage medium. Background Art

[0002] With the development of computer technology, in order to save development costs and improve software development efficiency, various code generators are currently provided on the Internet to assist programmers in completing software development.

[0003] Existing code generators can generate front-end pages, but they can usually only generate some useful code in advance and cannot generate functional code with multiple forms, resulting in a waste of code development time. Therefore, the inability of existing code generators to generate functional code with multiple forms has become an urgent problem that needs to be solved.

[0004] The above content is only used to assist in understanding the technical solution of the present invention and does not constitute an admission that the above content is prior art. Summary of the Invention

[0005] The main purpose of the present invention is to provide a code generation method, device, equipment and storage medium, aiming to solve the technical problem in the prior art that the code generator cannot generate functional code with multiple forms and improve software development efficiency.

[0006] To achieve the above object, the present invention provides a code generation method, which comprises the following steps:

[0007] When receiving the code generation instruction, searching the corresponding target data table from the preset database;

[0008] Parsing the target data table through a code generator to obtain target annotation information;

[0009] Searching for a corresponding target code block in a preset mapping relationship according to the target annotation information;

[0010] The target code block is copied to a code generation file, so that the code generator generates corresponding code according to the code generation file.

[0011] Optionally, before the step of searching the corresponding target data table from the preset database upon receiving the code generation instruction, the method further includes:

[0012] Obtain a newly added data table, and obtain corresponding target field information according to the function information of the newly added data table;

[0013] Acquire corresponding annotation information according to the target field information;

[0014] Writing the annotation information into the newly added data table to obtain a target data table containing the annotation information;

[0015] The target data table is stored in a preset database.

[0016] Optionally, the target annotation information includes table export annotation information;

[0017] Accordingly, after the step of copying the target code block to a code generation file so that the code generator generates corresponding code according to the code generation file, the method further includes:

[0018] When detecting that the table export annotation information exists in the target annotation information, generating a corresponding circle statement;

[0019] Query the data table information in the target data table through the circle statement;

[0020] The data table information is transmitted to an open source library so that the open source library generates a corresponding table file.

[0021] Optionally, the target annotation information includes mandatory item annotation information;

[0022] Accordingly, after the step of searching for the corresponding target code block in the preset mapping relationship according to the target annotation information, the method further includes:

[0023] Searching for a corresponding target required item code block in a preset mapping relationship according to the required item annotation information, and performing matching verification on the target required item code block;

[0024] When the match is successful, corresponding form verification information is generated to verify the input field information according to the form verification information.

[0025] Optionally, the target annotation information includes search annotation information;

[0026] Accordingly, the step of copying the target code block to a code generation file so that the code generator generates corresponding code according to the code generation file includes:

[0027] When detecting that the search annotation information exists in the target annotation information, obtaining a corresponding UI code block and a search code block in a preset mapping relationship according to the search annotation information;

[0028] Generate a corresponding search box according to the UI code block and the search code block;

[0029] The search box, the UI code block, and the search code block are copied to a code generation file, so that the code generator generates corresponding search codes according to the code generation file.

[0030] Optionally, before the step of copying the target code block to a code generation file so that the code generator generates corresponding code according to the code generation file, the step further includes:

[0031] Performing functional testing on functions corresponding to the target code block, the functions including adding, reading, updating and / or deleting;

[0032] When a functional test anomaly is detected, analyze the cause of the anomaly and determine the anomaly code;

[0033] Exception prompt information is generated based on the exception code, and the target code block is modified according to the exception prompt information.

[0034] Optionally, before the step of searching the corresponding target data table from the preset database upon receiving the code generation instruction, the method further includes:

[0035] Get the corresponding code block according to the annotation information;

[0036] A preset mapping relationship is generated based on the annotation information and the code block.

[0037] In addition, to achieve the above-mentioned purpose, the present invention further proposes a code generation device, comprising:

[0038] A data table search module is used to search for a corresponding target data table from a preset database when receiving a code generation instruction;

[0039] A data table parsing module, configured to parse the target data table through a code generator to obtain target annotation information;

[0040] A code block search module is used to search for a corresponding target code block in a preset mapping relationship according to the target annotation information;

[0041] The code generation module is used to copy the target code block to a code generation file so that the code generator generates corresponding code according to the code generation file.

[0042] In addition, to achieve the above-mentioned purpose, the present invention also proposes a code generation device, which includes: a memory, a processor, and a code generation program stored in the memory and executable on the processor, wherein the code generation program is configured to implement the steps of the code generation method described above.

[0043] In addition, to achieve the above-mentioned purpose, the present invention further proposes a storage medium, on which a code generation program is stored. When the code generation program is executed by a processor, the steps of the code generation method described above are implemented.

[0044] The present invention discloses that when a code generation instruction is received, a corresponding target data table is searched from a preset database; the target data table is parsed by a code generator to obtain target annotation information; the corresponding target code block is searched in a preset mapping relationship according to the target annotation information; the target code block is copied to a code generation file, so that the code generator generates corresponding code according to the code generation file; compared with the problem that the front-end page generated by the code generator in the prior art can only provide an ordinary input box and does not support the generation of diversified controls, the present invention parses the target data table searched from the preset database by a code generator to obtain target annotation information, and copies the target code block obtained through the target annotation information to the code generation file, so that the code generator can generate corresponding code through the code generation file, thereby solving the technical problem that the existing code generator cannot generate functional code with multiple forms, thereby improving software development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 It is a structural diagram of a code generation device in a hardware operating environment involved in an embodiment of the present invention;

[0046] Figure 2 This is a flow chart of a first embodiment of a code generation method according to the present invention;

[0047] Figure 3 This is a flow chart of a second embodiment of the code generation method of the present invention;

[0048] Figure 4 This is a flow chart of a third embodiment of the code generation method of the present invention;

[0049] Figure 5 This is a structural block diagram of the first embodiment of the code generation device of the present invention.

[0050] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION

[0051] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0052] Reference Figure 1 , Figure 1 This is a schematic diagram of the code generation device structure of the hardware operating environment involved in the embodiment of the present invention.

[0053] like Figure 1 As shown, the code generation device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk storage. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0054] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation to the code generating device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0055] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a code generation program.

[0056] exist Figure 1 In the code generation device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the code generation device of the present invention can be set in the code generation device. The code generation device calls the code generation program stored in the memory 1005 through the processor 1001 and executes the code generation method provided by the embodiment of the present invention.

[0057] The embodiment of the present invention provides a code generation method, referring to Figure 2 , Figure 2 Schematic diagram of the flow of the first embodiment of the code generation method of the present invention.

[0058] In this embodiment, the code generation method includes the following steps:

[0059] Step S10: When receiving the code generation instruction, searching for the corresponding target data table from the preset database.

[0060] It should be noted that the execution subject of the method of this embodiment can be a code generation device that generates code, or other code generation systems that can achieve the same or similar functions and include the code generation device. Here, the code generation method provided in this embodiment and the following embodiments is specifically described using a code generation system (hereinafter referred to as the system).

[0061] It should be understood that the above-mentioned code generation instructions may be instructions received by the system when developing code. The code generation instructions may include the functions that the generated code needs to implement or the functions that need to be implemented corresponding to the data table, so that the system can search the corresponding data table from the database according to the above-mentioned functions that need to be implemented.

[0062] It is understandable that the above-mentioned preset database may be a database storing multiple data tables. After receiving the above-mentioned code generation instruction, the system may search for the corresponding data table from the preset database according to the prompt information contained in the code generation instruction.

[0063] It should be noted that the target data tables may be data tables pre-stored in a preset database and designed according to business needs, such as a test question table, a score table, and an employee table.

[0064] Step S20: parsing the target data table through a code generator to obtain target annotation information.

[0065] It should be understood that the code generator described above can be a tool for generating code or for compiling computer programs. The code generator can be built based on a computer language template engine and support database connections such as MySQL, SQL Server, and Oracle. It can also perform functions such as text generation and, through plug-ins, can support matching and generation of arbitrary file formats.

[0066] It is understood that the target annotation information can include all characteristic strings contained in the target data table, such as required fields '*', matching search '@s', fuzzy search '@sl', date '@d8', single image '@p', multiple images '@pm', single file '@f', multiple files '@fm', non-input fields '@nw', static drop-down selection '[key:val,key:val', dynamic drop-down selection '[class.attr=', and table export '@exportExcel', etc. These characteristic strings can be used to generate control-like code. Different annotation information can represent different functionalities, and the corresponding code generated from the annotation information can also implement different functions. For example, '@s' indicates the generation of a control that supports search, '@p' indicates the generation of a control that supports image uploads, and '@f' indicates the generation of a control that supports file uploads. In actual applications, the system can traverse the data table through a code generator and analyze the characteristic strings present in the data table to obtain information such as the names and functions corresponding to the characteristic strings.

[0067] Step S30: searching for a corresponding target code block in a preset mapping relationship according to the target annotation information.

[0068] It should be noted that the above-mentioned preset mapping relationship can be a correspondence between annotation information and code blocks. Different annotation information has corresponding standard code blocks, and then a mapping relationship is established based on the annotation information and the standard code block corresponding to the annotation information. Among them, the standard code can be a code block pre-set by the programmer according to the function that needs to be implemented by the annotation information.

[0069] It can be understood that the above-mentioned target code blocks can be all code blocks corresponding to all annotation information in the data table. For example: when the annotation information is '@s', the corresponding target code block is the code for implementing the search function; when the annotation information is '@p', the corresponding target code block is the code for implementing the image upload function; when the annotation information is '@f', the corresponding target code block is the code for implementing the file upload function.

[0070] Step S40: copying the target code block to a code generation file, so that the code generator generates corresponding code according to the code generation file.

[0071] It should be noted that the above-mentioned code generation file can be a pre-established file that stores code blocks required to implement the functions existing in the current development business. After the code generation file is established, a prompt signal can be sent to the code block, so that when code generation is required, the code generator can directly generate code through the code generation file, and then implement the functions required for business development by running the generated code.

[0072] It can be understood that when the system traverses the annotation information in the above-mentioned target data table, it can obtain all the annotation information in the target data table, and obtain all the corresponding code blocks based on these annotation information, and at the same time copy all the code blocks into the pre-established code development file. After the code development file is established, a download button can be generated. When you need to generate code, you can click this download button. At this time, you can download the code in the code generation file and directly run the code to realize the functions required by the currently developed business.

[0073] In the specific implementation, if you want to develop a question table business, you can first create a question table and store the created question table in the preset database. When you need to use the question table, you can generate corresponding code to implement functions such as search, image upload and file upload in the question table. At this time, you can get the question table from the preset database and query the annotation information in the question table. For example, if you need to add a search function to the question content column in the question table, there will be a corresponding search annotation for the question content in the question table. When the code generator finds the search annotation '@s', it will search and match before and after the annotation. The content of the annotation can be: `question_content` VARCHAR(800) NULL DEFAULT NULL COMMENT'@stest question content*', and obtain the corresponding search code according to the annotation content. After obtaining the search code, you can save the search code to the code generation file corresponding to the test question table. When the code generator saves the code blocks corresponding to all the annotation information in the test question table to the code generation file corresponding to the test question table, it generates a corresponding download button. When the test question table needs to be put into use, click the download button to download the code in the code generation file, so that the code generator can realize the search, image upload and file upload functions in the test question table according to the downloaded code.

[0074] Furthermore, in order to enable the generated code to have the functions of adding, reading, updating and / or deleting multiple forms, the above method of this embodiment also includes: performing functional testing on the functions corresponding to the target code block, the functions including adding, reading, updating and / or deleting; when a functional test exception is detected, analyzing the cause of the exception and determining the exception code; generating exception prompt information based on the exception code, and modifying the target code block according to the exception prompt information.

[0075] It is understandable that due to the continuous updates of the code generator and database, or other code running software, data is prone to loss or incompatibility problems during transmission or between different running device versions. At this time, when generating the corresponding code generation file, it is necessary to perform functional testing on the obtained code blocks to check whether there are any abnormalities in the functions of adding, reading, updating and / or deleting corresponding to these code blocks. If there are no abnormalities, the above-mentioned code generation file can be generated normally. If there are abnormalities, the code blocks need to be tested and the cause of the abnormality is analyzed. According to the analysis results, the abnormal code is determined and an abnormal prompt message is generated, thereby prompting the corresponding staff or code developers to modify the abnormal code.

[0076] The present embodiment discloses that when receiving a code generation instruction, a corresponding target data table is searched from a preset database; the target data table is parsed by a code generator to obtain target annotation information; the corresponding target code block is searched in a preset mapping relationship according to the target annotation information; the target code block is copied to a code generation file so that the code generator generates corresponding code according to the code generation file; compared with the problem that the front-end page generated by the code generator in the prior art can only provide a common input box and does not support the generation of diversified controls, since the present embodiment parses the target data table found from the preset database by the code generator to obtain target annotation information, and copies the target code block obtained by the target annotation information to the code generation file, the code generator can generate corresponding code through the code generation file, solving the technical problem that the existing code generator cannot generate functional code with multiple forms, thereby improving software development efficiency. The code generator in this embodiment can generate corresponding code based on annotation information, while the function of the existing database annotation information is to mark in the code and prompt code generation, and cannot generate code through annotation information, thereby improving work efficiency. At the same time, the obtained code blocks can also be tested before generating the code generation file to check whether there are any abnormalities in the code function. If there are any abnormalities, the abnormal code is determined and the abnormal code is modified according to the abnormal analysis results to ensure the integrity and accuracy of the generated code function, further improving software development efficiency.

[0077] refer to Figure 3 , Figure 3 Schematic diagram of the flow of the second embodiment of the code generation method of the present invention.

[0078] Based on the first embodiment described above, in order to establish a corresponding data table according to the business to be developed, in this embodiment, before step S10, the method further includes:

[0079] Step S01: Acquire a newly added data table, and acquire corresponding target field information according to the function information of the newly added data table.

[0080] It should be noted that the above-mentioned newly added data tables can be data tables created by designing user interface function diagrams when developing new businesses. For example, when it is necessary to count employee information, a new employee table is added; when it is necessary to count student grades, a new grade table is added; when it is necessary to set questions for students, a new test question table is added, etc.

[0081] It is understandable that the above functional information may be functions that need to be implemented in each part of the data table, such as image upload, file upload, and file export functions.

[0082] It should be understood that the above-mentioned target field information may be the corresponding prompt content entered when establishing the data table. For example, when the data table is a test question table, the field information may be information such as uploaded avatar, test question content and answers.

[0083] Step S02: Acquire corresponding annotation information according to the target field information.

[0084] It should be noted that the above-mentioned annotation information can be the annotation required for this field information obtained after analyzing the obtained field information. For example: when the field information is uploading an avatar, the corresponding annotation information is the characteristic string '@p' corresponding to the picture upload; when the field information is a title, the corresponding annotation information is the characteristic string '*' corresponding to the required item; when the field information is adding time, the corresponding annotation information is the characteristic string '@d8' corresponding to the date, etc.

[0085] Step S03: writing the annotation information into the newly added data table to obtain a target data table containing the annotation information.

[0086] It should be understood that the target data table may be a data table containing all annotation information corresponding to the functional information in the newly added data table.

[0087] Step S04: storing the target data table in a preset database.

[0088] In the specific implementation, if the newly added data table is an employee table, when designing the employee table, if you need to upload a avatar, you can add the annotation information '@p' that allows you to upload a picture in the upload avatar field, thereby realizing the function of uploading the corresponding avatar picture in the upload avatar field. If the employee's name, age, place of origin and other information are required information, you can add the required annotation information '*' to the fields corresponding to the employee's name, age, and place of origin. If the employee does not fill in the employee's name, age, place of origin and other information when filling in the employee form, a prompt message will appear when the employee submits the form to prompt the employee to fill in the required content. After the annotation information corresponding to the target field in the data table is added, a target data table can be generated and stored in the preset database. Therefore, when you need to use the employee table, you can directly obtain the pre-established employee table in the preset database.

[0089] This embodiment adds a new data table, obtains corresponding field information according to the functions that the new data table needs to implement, analyzes the field information, obtains corresponding annotation information, and stores the target data table containing the annotation information in a preset database. When code needs to be generated, the corresponding target data table is directly obtained from the preset database according to the information of the code to be generated, and the corresponding code is generated based on the target data table, thereby reducing the workload of staff and improving work efficiency.

[0090] refer to Figure 4 , Figure 4 FIG. 4 is a flow chart of the third embodiment of the code generation method of the present invention.

[0091] Based on the above embodiments, in order to enable the information in the data table to be exported through a table, in this embodiment, after step S40, the method further includes:

[0092] Step S50: When it is detected that the table export annotation information exists in the target annotation information, a corresponding circle statement is generated.

[0093] It should be noted that the above table export annotation information may be a characteristic string that enables the information in the data table to be exported through the table, for example: @exportExcel.

[0094] It should be understood that the above circle statement can be a function or code for querying data in a data table, and the queried data can be transmitted to a preset location or area through circle.

[0095] Step S60: querying the data table information in the target data table through the circle statement.

[0096] It is understandable that the above-mentioned data table information may be field information, annotation information, name information, etc. in the data table.

[0097] Step S70: Transmitting the data table information to an open source library, so that the open source library generates a corresponding table file.

[0098] It should be noted that the above-mentioned open source library can be a firmware in an object-oriented programming language, which can provide an application interface to the object-oriented programming program to read and write the table file. After receiving the information in the data table, the open source library can write this information into the table file, thereby generating a table file containing the data table information.

[0099] In the specific implementation, after traversing the data table, the system finds that there is the @exportExcel feature string in the data table, which means that a spreadsheet file needs to be exported. At this time, a circle statement can be generated to query the field information, annotation information, name and other information in the data table, and the queried data table information is transmitted to the open source function library, so that the open source function library can write the data table information into the spreadsheet file and export the generated spreadsheet file containing the data table information.

[0100] Furthermore, in order to verify the content of the required items in the data table, the above method of this embodiment also includes: searching for the corresponding target required item code block in the preset mapping relationship according to the required item annotation information, and matching and verifying the target required item code block; when the match is successful, generating corresponding form verification information to verify the input field information according to the form verification information.

[0101] It should be noted that the above mandatory annotation information can be a characteristic string that marks the content that must be filled in the data table, for example: the characteristic string '*'. When the name in the data table is followed by '*', it means that the name is mandatory content.

[0102] In the specific implementation, if the data table is an employee table, the code generator detects that there is a characteristic string '*' in the fields corresponding to the name, age, and telephone number in the employee table, indicating that this information is required. At this time, the code generator successfully matches the characteristic string '*' and generates the corresponding form verification information. If the characteristic string '*' is not found in the employee table, it means that there is no required information, then the match is unsuccessful and no processing is required. There are fixed verification codes in the form verification information. For example, the age field must be a numeric type. If the numeric type is 0, the code generator can determine whether the value of the age field is 0 based on the code for determining the numeric type in the form verification information. If it is 0, it will prompt that the age field is required. If the name length corresponding to the name field can only be 50 characters, the name length will be marked when the data table is created. After reading the name length information, the code generator will limit the name field to 50 characters so that the input characters do not exceed 50 characters. When using the employee table, if the entered age is not a numeric type or the entered name exceeds 50 characters, input will be prohibited and a corresponding prompt message will be generated to prompt the user to enter information according to regulations.

[0103] Furthermore, in order to add a search function to the data table, the above method of this embodiment also includes: when it is detected that the search annotation information exists in the target annotation information, obtaining the corresponding UI code block and search code block in the preset mapping relationship according to the search annotation information; generating a corresponding search box according to the UI code block and the search code block; copying the search box, the UI code block and the search code block to the code generation file, so that the code generator generates the corresponding search code according to the code generation file.

[0104] It should be understood that the above search annotation information may be a characteristic string corresponding to the search function in the data table, for example: @s.

[0105] It is understandable that the above UI code block may be a code block for implementing the style of the search box interface in the data table, such as sliding search, scrolling search, etc.

[0106] It should be noted that the above-mentioned search code block can be a code block corresponding to the search function in the data table. If the search function does not exist in the data table, there will only be lists of adding, deleting, editing and displaying. If the search function exists, a new search box can be added. For example, in an employee table, when searching for an employee name through the search box, the employee information corresponding to the employee can be found.

[0107] In the specific implementation, when the code generator traverses the information in the data table and finds the annotation information '@s', it means that the search function needs to be implemented in the data table. At this time, the UI code block and search code block corresponding to the annotation information '@s' can be found in the preset database, and a search box with a search style can be generated through the UI code and search code, and the generated search box and the corresponding UI code block and search code block are saved in the code generation file. When using the data table, the search function can be implemented by running the code in the code generation file.

[0108] This embodiment detects annotation information in the data, generates a corresponding circle statement when table export annotation information is detected, and transmits the information in the queried data table to the open source library through the circle statement, thereby exporting the table file generated by the open source library; when required annotation information is detected, form verification information is generated according to the required code block corresponding to the required annotation information, thereby verifying the input field information; when search annotation information is detected, a corresponding search box is generated according to the UI code block and search code block corresponding to the search annotation information, thereby realizing the search function in the data table. This embodiment can realize multi-forms through the generated code generation file, and supports the functions of search, table file export and automatic code generation, and does not require a large amount of control configuration, reducing the workload and thus improving work efficiency.

[0109] In addition, an embodiment of the present invention further provides a storage medium, on which a code generation program is stored. When the code generation program is executed by a processor, the steps of the code generation method described above are implemented.

[0110] Reference Figure 5 , Figure 5 This is a structural block diagram of the first embodiment of the code generation device of the present invention.

[0111] like Figure 5 As shown, the code generation device proposed in the embodiment of the present invention includes:

[0112] Data table search module 501: used to search for the corresponding target data table from the preset database when receiving the code generation instruction;

[0113] Data table parsing module 502: used to parse the target data table through a code generator to obtain target annotation information;

[0114] Code block search module 503: used to search for the corresponding target code block in the preset mapping relationship according to the target annotation information;

[0115] The code generation module 504 is used to copy the target code block to a code generation file, so that the code generator generates corresponding code according to the code generation file.

[0116] The code generation device of this embodiment discloses that when receiving a code generation instruction, it searches for a corresponding target data table from a preset database; parses the target data table through a code generator to obtain target annotation information; searches for a corresponding target code block in a preset mapping relationship according to the target annotation information; copies the target code block to a code generation file, so that the code generator generates corresponding code according to the code generation file; compared with the problem that the front-end page generated by the code generator in the prior art can only provide an ordinary input box and does not support the generation of diversified controls, since this embodiment parses the target data table found from the preset database through a code generator to obtain target annotation information, and copies the target code block obtained through the target annotation information to the code generation file, the code generator can generate the corresponding code through the code generation file, thereby solving the technical problem that the existing code generator cannot generate functional code with multiple forms, thereby improving software development efficiency.

[0117] Other embodiments or specific implementations of the code generation device of the present invention can refer to the above-mentioned method embodiments and will not be described in detail here.

[0118] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or system comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or system. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or system comprising the element.

[0119] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.

[0120] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as read-only memory / random access memory, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0121] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A code generation method, characterized in that: The code generation method comprises: When receiving the code generation instruction, searching the corresponding target data table from the preset database; Parsing the target data table through a code generator to obtain target annotation information, wherein the target annotation information includes table export annotation information, and the table export annotation information is a characteristic character string that enables information in the target data table to be exported through a table; Searching for a corresponding target code block in a preset mapping relationship according to the target annotation information; Copying the target code block to a code generation file so that the code generator generates corresponding code according to the code generation file; After the step of copying the target code block to a code generation file so that the code generator generates corresponding code according to the code generation file, the method further includes: When detecting that the table export annotation information exists in the target annotation information, generating a corresponding circle statement, wherein the circle statement is a function for querying the data in the target data table; Query the data table information in the target data table through the circle statement; Transmitting the data table information to an open source library so that the open source library generates a corresponding table file; Before the step of searching the corresponding target data table from the preset database upon receiving the code generation instruction, the method further includes: Obtain a newly added data table, and obtain corresponding target field information according to the function information of the newly added data table; Acquire corresponding annotation information according to the target field information; Writing the annotation information into the newly added data table to obtain a target data table containing the annotation information; Storing the target data table in a preset database; The target annotation information includes mandatory annotation information; Accordingly, after the step of searching for the corresponding target code block in the preset mapping relationship according to the target annotation information, the method further includes: Searching for a corresponding target required item code block in a preset mapping relationship according to the required item annotation information, and performing matching verification on the target required item code block; When the match is successful, the corresponding form verification information is generated to verify the input field information according to the form verification information; The target annotation information includes search annotation information; Accordingly, the step of copying the target code block to a code generation file so that the code generator generates corresponding code according to the code generation file includes: When detecting that the search annotation information exists in the target annotation information, obtaining a corresponding UI code block and a search code block in a preset mapping relationship according to the search annotation information; Generate a corresponding search box according to the UI code block and the search code block; The search box, the UI code block, and the search code block are copied to a code generation file, so that the code generator generates corresponding search codes according to the code generation file.

2. The code generation method according to claim 1, wherein: Before the step of copying the target code block to a code generation file so that the code generator generates corresponding code according to the code generation file, the method further includes: Performing functional testing on functions corresponding to the target code block, the functions including adding, reading, updating and / or deleting; When a functional test anomaly is detected, analyze the cause of the anomaly and determine the anomaly code; Exception prompt information is generated based on the exception code, and the target code block is modified according to the exception prompt information.

3. The code generation method according to claim 1, wherein: Before the step of searching the corresponding target data table from the preset database upon receiving the code generation instruction, the method further includes: Get the corresponding code block according to the annotation information; A preset mapping relationship is generated based on the annotation information and the code block.

4. A code generating device, characterized in that: The device comprises: A data table search module is used to search for a corresponding target data table from a preset database when receiving a code generation instruction; a data table parsing module, configured to parse the target data table through a code generator to obtain target annotation information, wherein the target annotation information includes table export annotation information, and the table export annotation information is a characteristic string that enables information in the target data table to be exported through a table; A code block search module is used to search for a corresponding target code block in a preset mapping relationship according to the target annotation information; A code generation module, configured to copy the target code block to a code generation file, so that the code generator generates corresponding code according to the code generation file; The code generation module is further configured to, upon detecting the presence of the table export annotation information in the target annotation information, generate a corresponding circle statement, wherein the circle statement is a function for querying data in the target data table; query data table information in the target data table using the circle statement; and transmit the data table information to an open source library so that the open source library generates a corresponding table file; The data table search module is further configured to obtain a newly added data table, and obtain corresponding target field information based on the function information of the newly added data table; obtain corresponding annotation information based on the target field information; write the annotation information into the newly added data table to obtain a target data table containing the annotation information; and store the target data table in a preset database; The target annotation information includes mandatory annotation information; the code block search module is further used to search for a corresponding target mandatory code block in a preset mapping relationship according to the mandatory annotation information, and perform matching verification on the target mandatory code block; when the match is successful, generate corresponding form verification information to verify the input field information according to the form verification information; The target annotation information includes search annotation information; the code block search module is also used to obtain the corresponding UI code block and search code block in a preset mapping relationship according to the search annotation information when detecting the presence of the search annotation information in the target annotation information; generate a corresponding search box according to the UI code block and the search code block; copy the search box, the UI code block and the search code block to a code generation file, so that the code generator generates the corresponding search code according to the code generation file.

5. A code generating device, characterized in that: The device includes: a memory, a processor, and a code generation program stored in the memory and executable on the processor, wherein the code generation is configured to implement the steps of the code generation method according to any one of claims 1 to 3.

6. A storage medium, characterized in that The storage medium stores a code generation program, which, when executed by a processor, implements the steps of the code generation method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Code generation method and device

    CN109189379A

  • File generation method and device, equipment and storage medium

    CN113760360A

  • Code generation method, terminal and readable storage medium

    CN114115826A

  • Software application testing method and device, equipment and storage medium

    CN114238110A