Code generation method and system and storage medium
A centralized code generation system on a server maintains uniformity and simplicity by generating and sending code templates to clients, reducing development complexity and enhancing security and flexibility for large teams.
Patent Information
- Application Number
- CN202411587177.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2024-12-06
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Current code generation methods are prone to complex operation processes and inconvenient use due to inconsistent code generation processes, limiting their application in large teams seeking efficient collaboration and simplified development processes.
A centralized code generation system where rules are maintained on a server, ensuring uniformity and simplicity by generating code templates based on project parameters, compressing them into a file package, and sending it to the client for execution, while maintaining security and simplicity through permission checks.
This approach reduces development difficulty, enhances compatibility and flexibility, ensures secure code generation, and simplifies maintenance by automating code migration and configuration, making it suitable for large-scale software projects.
Smart Images

Figure CN119088364A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a code generation method, system and storage medium. Background Art
[0002] The current code generation schemes include a code generation mode based only on the client (C-end) and a code generation mode based only on the server (S-end). In the code generation mode based only on the client (C-end), code generation is controlled by the C-end, but everyone can modify the generation rules by themselves during collaborative development, which is not convenient for unified management and is not easy to use; while in the code generation mode based only on the server (S-end), when collaborative development is in progress, developers need to manually download the generated code from the S-end and then manually migrate and paste it into their own projects. The operation process is complicated and increases the development difficulty of the C-end.
[0003] Therefore, in actual use, both code generation modes are prone to complex operation processes and inconvenient use due to the inconsistency of the code generation process. This limitation still limits its application in a wider range of scenarios for large teams that pursue efficient collaboration and simplified development processes. Therefore, seeking a method to ensure the uniformity and simplicity of code generation for different projects has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] In view of this, the embodiments of the present application provide a code generation method, system and storage medium, which can effectively solve the technical problems in the prior art that the operation process is complicated and the use is not easy due to the non-uniform code generation process of different projects.
[0005] In a first aspect, the present application provides a code generation method, which is applied to a server, comprising: Receive a code generation request initiated by a client, wherein the code generation request carries project parameters of a project to be developed; According to the project parameters, determine a project database associated with the project parameters from internally stored project maintenance information, and obtain table structure data in the project database; the table structure data includes project data and data structure for generating code texts, and generation rules for indicating code templates; Generate a code template based on the generation rule, and generate a plurality of code files according to the project data, the data structure and the code template; each of the code files contains a code coverage rule; Each of the code files is compressed into a file package and then sent to the client, so that the client decompresses the file package to run the code coverage rules in each of the code files to obtain executable code for the target project.
[0006] In an optional implementation manner, after receiving the code generation request initiated by the client, the method further includes: Performing a permission check on the client according to the code generation request to determine whether the client has the permission to generate the executable code of the project to be developed; If the permission check is passed, respond to the code generation request and perform a code generation operation; If the permission check fails, a no-authorization-to-operate message is returned to the client.
[0007] In an optional implementation manner, before receiving the code generation request initiated by the client, the method further includes: Different projects to be developed and project maintenance information of each of the projects are created, wherein the project maintenance information includes a project name and a project database associated with the project name; the project database includes table structure data, code templates and code coverage rules.
[0008] In a second aspect, the present application provides a code generation method, applied to a client, comprising: After initiating a code generation request to the server, receiving the file package output by the server; After the file package is decompressed, the code coverage rules of each code file in the file package are run to add each code file to the storage path corresponding to the target project according to the coverage method corresponding to the code coverage rule to obtain executable code.
[0009] In an optional implementation manner, before initiating a code generation request to the server, the method further includes: Configure a code generation plug-in and generate dependency information of the code generation plug-in; the dependency information includes project parameters of the project to be developed, and the project parameters are used to generate a code generation request; The code generation plug-in is used to respond to the code generation command, generate a code generation request, and execute the steps of receiving the compressed data packet containing the code file output by the server, decompressing the compressed data packet, and running the code coverage rules in each of the code files to obtain the executable code.
[0010] In an optional implementation, each of the code files is stored in the file package according to a storage location index, and the running of the code coverage rule of each code file in the file package to add each of the code files to the storage path corresponding to the target project according to the coverage method corresponding to the code coverage rule includes: Run the code coverage rules in each of the code files in sequence; the code coverage rules are used to indicate the coverage mode and storage path of the code files; After executing the file overwriting logic according to the overwriting method for each of the code files, the code files are added to the storage path according to the storage location index of each of the code files.
[0011] In an optional embodiment, it also includes: In response to the code update instruction, determining a target code file storing the executable code to be updated indicated in the code update instruction and a code coverage rule for the target code file; If it is determined that the code coverage rule indicates that the code can be updated, then updating the corresponding executable code according to the code update instruction; If it is determined that the code coverage rule indicates that the code cannot be updated, information that the code cannot be updated is fed back.
[0012] In a third aspect, the present application provides a code generation system, comprising: Client, used to initiate code generation request; A server, used for receiving the code generation request, to execute the aforementioned code generation method, and to send a file package to the client; The client is also used to receive the file package to execute the aforementioned code generation method.
[0013] In a fourth aspect, the present application provides an electronic device, comprising a processor and a memory, wherein the memory stores a computer program, and the processor is used to execute the computer program to implement the aforementioned code generation method or the aforementioned code generation method.
[0014] In a fifth aspect, the present application provides a computer storage medium storing a computer program, which, when executed on a processor, implements the aforementioned code generation method or the aforementioned code generation method.
[0015] The embodiments of the present application have the following beneficial effects: An embodiment of the present application provides a code generation method, which, when applied to a server, includes: receiving a code generation request initiated by a client, the code generation request carrying project parameters of a project to be developed; determining, based on the project parameters, a project database associated with the project parameters from internally stored project maintenance information, and acquiring table structure data in the project database; the table structure data includes project data and a data structure for generating code text, and generation rules for indicating code templates; generating code templates based on the generation rules, and generating multiple code files based on the project data, the data structure and the code templates; each code file includes a code coverage rule; and after compressing each code file into a file package, sending the package to the client in a data stream manner, so that the client can decompress the file package to run the code coverage rules in each code file to obtain executable code for the target project. The embodiment of the present application ensures the uniformity of code development for different projects by maintaining code generation rules for different projects to be developed on the server side, responding to the client's code generation requirements to execute the code generation operation for the target project, and then sending the generated code file to the client side. The client side is then used as the responding end for code generation, automatically receiving the code file generated by the server side, and running the code generation logic in the code file, thereby automatically migrating the code generated by the server side to the local target project path of the client side. Subsequently, the executable code can be directly run on the client side to complete the development of the target project without the client having to perform additional development work, thereby reducing the development difficulty of the client side, reducing the complexity of the code generation process, and improving the security and simplicity of the code generation process. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 A schematic diagram of the structure of a code generation system in an embodiment of the present application is shown; Figure 2 A first schematic flow chart of a code generation method in an embodiment of the present application is shown; Figure 3 A second schematic flow chart of the code generation method in an embodiment of the present application is shown; Figure 4 A third flow chart of the code generation method in an embodiment of the present application is shown; Figure 5 A first structural schematic diagram of a code generating device in an embodiment of the present application is shown; Figure 6 A second structural schematic diagram of the code generation device in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0018] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0019] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0020] Hereinafter, the terms "including", "having" and their cognates that can be used in various embodiments of the present application are intended only to indicate specific features, numbers, steps, operations, elements, components or a combination of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or a combination of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or a combination of the foregoing items. In addition, the terms "first", "second", "third" and the like are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance.
[0021] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.
[0022] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0023] This embodiment provides a code generation system, such as Figure 1As shown, the system includes a server 100 and a client 200, wherein the system avoids the problem of scattered code generation rules by maintaining the code generation rules of each project to be developed on the server 100. Therefore, the code generation rules only need to be maintained on the server, and the client cannot easily change the rules. If the code generation rules need to be changed, the code rule modification authority of the server must be obtained to complete the rule modification action, thereby ensuring the security of the code generation rules; further, the server 100 responds to the code generation requirements of the client 200 to perform the code generation operation of the target project, thereby ensuring the uniformity of code generation; and then the server 100 The code file is sent to the client 200, and the client 200 is then used as the responding end of the code generation. It automatically receives the code file generated by the server 100 and runs the code generation logic in the code file, thereby automatically migrating the code generated by the server 100 to the local target project path of the client 200. The executable code can then be directly run on the client 200 to complete the development of the target project without the need for additional development work, thereby reducing the development difficulty of the client 200 and solving the problem of manual overwriting or transfer of directories for code generation, reducing the complexity of the code generation process and improving the security and simplicity of the code generation process.
[0024] Furthermore, since code generation is completed on the server 100, it is not restricted by a specific development environment (IDE). This allows different types of developers, regardless of which IDE they use or whether they have no IDE, to use the server 100 to generate code, thereby greatly enhancing the compatibility and flexibility of the code generation system. In addition, the server 100 can strictly control which clients or applications can generate code through the API authorization mechanism, thereby protecting sensitive information and intellectual property rights to ensure the security of access rights and code generation. In addition, the configuration information of all projects to be developed is centrally stored on the server 100, which can be more easily managed and updated in a unified manner, reducing the risk of configuration errors, while also simplifying the maintenance process, making the project code development process more stable and easy to expand.
[0025] Optionally, the server 100 includes but is not limited to a server or an electronic device such as a computer; the client 200 includes but is not limited to an electronic device such as a terminal device, a computer, etc.
[0026] For example, Figure 2 As shown, the server 100 performs the code generation process including the following steps: S110, receiving a code generation request initiated by the client 200, where the code generation request carries project parameters of the project to be developed.
[0027] S120, according to the project parameters, determine the project database associated with the project parameters from the internally stored project maintenance information, and obtain the table structure data in the project database; wherein the table structure data includes the project data and data structure for generating the code text, and the generation rules for indicating the code template.
[0028] S130, generating a code template based on the generation rule, and generating a plurality of code files according to the project data, the data structure and the code template.
[0029] S140, compressing each code file into a file package and sending it to the client 200, so that the client 200 decompresses the file package to run the code coverage rules in each code file to obtain the executable code of the target project.
[0030] Exemplarily, the server 100 pre-creates different projects to be developed and project maintenance information of each project, wherein the project maintenance information of each project includes a project name and a project database associated with the project name; the project database includes table structure data, code templates and code coverage rules.
[0031] Furthermore, a database instance related to each project is created in advance, and the data relationship between different data objects that may exist in each project is defined. The project database of the project is created according to the database instance, and the data relationship between each data object is converted into table structure data in the project database. Among them, a database configuration tool or a command line can be used to create a database instance, and necessary permissions and security measures can be set to control the access rights of the subsequently generated project database. In addition, the present embodiment can also complete the creation of the table structure and data migration through methods such as SQL scripts or visualization tools.
[0032] In this process, the server 100 can also compile code templates for each project, such as functions, classes, interfaces, etc., and store the code templates in the database of the project so that the code templates can be directly called to generate the code for the project in the future, thereby reducing repeated coding work and improving development efficiency. In addition, code coverage rules are set in each code template of the same project so that the client 200 can run the code coverage rules to complete the migration and coverage of code files.
[0033] For reference, the server 100 receives a code generation request from the client 200 through a corresponding network interface (such as HTTP or HTTPS). The client 200 usually sends the code generation request through a POST or GET method, wherein the code generation request carries a project parameter, which is used to indicate the project to be developed (i.e., the target project) for which code generation is currently required, so that the server 100 performs a code generation operation on the project. The project parameter includes, but is not limited to, the project name of the project to be developed, which can be adaptively set according to actual needs, and this embodiment does not limit this.
[0034] The server 100 parses the received code generation request, searches for a matching project database in the internally stored project maintenance information according to the project parameters carried by the code generation request, and obtains table structure data from the matching project database; wherein the table structure data includes but is not limited to project data (data describing the project itself, such as project identification, version information, configuration parameters, etc.), data structure (including table names, field names, field types, constraints, etc. in the project database), code generation rules (rules for indicating how to use table structure data to generate code, such as class names, attribute naming, method definitions, etc.), and code template generation rules or code templates. Among them, the table structure data can also be specifically set according to actual needs, and this embodiment does not limit this.
[0035] A code template is generated according to the generation rule of the code template, wherein the code template includes a placeholder, and the placeholder is used to fill in the project data; then, the project data in the table structure data and its corresponding data structure are used to replace the placeholder to generate a code file, that is, fill the project data into the code template according to the data structure. Among them, each code file corresponds to a specific functional module or class of the target project. That is, each functional module or method class in the target project is presented by a code file, and the subsequent client 200 runs the code file, which is to run the functional module or method class. Among them, the code template is set accordingly with the project type. Different projects can use the same code template or different code templates. The specific code template setting rules can be adjusted accordingly according to needs, and there is no limitation on this.
[0036] It should be noted that, in the process of generating code files, the server 100 embeds corresponding code coverage rules in each code file, and the code coverage rules are used to indicate the coverage method of the code file and the storage path of the code file when the client 200 migrates the code file. Among them, the code coverage rules of various code files of the same project can be the same or different, which can be set accordingly according to actual needs, and this embodiment does not limit this.
[0037] Optionally, the timing and method of issuing code coverage rules can be set according to actual needs; for example, the code coverage rules corresponding to each code file in the same project can be embedded into the corresponding code file by server 100 during the code generation phase of server 100; or, server 100 does not embed the code coverage rules into the code file during the code generation phase, but instead requests the code coverage rules corresponding to the code file from server 100 during the process of client 200 decompressing and running the code file. Server 100 sends the code coverage rules to client 200 at this stage, so that client 200 runs the code file according to the separately received code coverage rules, thereby completing the code coverage logic and realizing project code generation of client 200.
[0038] Furthermore, the server 100 compresses and packages the generated multiple code files into a file package, wherein each code file is stored in the same file package according to the corresponding storage location index, and the type of the file package depends on the selected compression algorithm, and this embodiment does not limit the compression process and compression algorithm. Optionally, the format of the file package can be a ZIP or TAR format. This embodiment can reduce the amount of data transmitted by compressing and packaging multiple code files for transmission, thereby improving transmission efficiency.
[0039] Optionally, the compressed file package can be sent to the client 200 in a data stream through the network. The data stream transmission process allows the client 200 to start decompression and processing when receiving a part of the file package, without waiting for the entire file package to be transmitted, thereby improving the code generation efficiency of the client 200.
[0040] In one embodiment, after receiving the code generation request from the client 200, the server 100 may perform a permission check on the client 200, thereby controlling access rights and ensuring security during the project code generation process. According to the code generation request, the client 200 that initiates the request is subjected to a permission check to determine whether the client 200 has the permission to generate executable code for the target project; if the permission check passes, the code generation request is responded to and the code generation operation is performed; if the permission check fails, a message indicating that the operation is not authorized is returned to the client 200.
[0041] That is, the present embodiment can also implement authority management to complete the isolation of different projects. For example, the client 200 initiates code generation requests for one or more projects according to its own authority; the server 100 implements authority management and code generation management, responds to code generation requests according to the authority of the client 200, and uniformly executes the code development process of different projects. Among them, the client 200 can only initiate code generation requests for projects within its own authority. For example, if the client 200 is only allowed to participate in the code development of project A, the client 200 can only initiate code generation requests for project A, and cannot initiate code generation requests for project B; if the client 200 initiates a code generation request for project B, the server 100 will not execute the code generation process of project B for the client 200 after completing the authority check of the client 200. Furthermore, while ensuring the security of the code generation process, most of the code generation logic is configured on the server 100, and the client 200 only needs a very simple configuration to use it. The code generation process of the client 200 does not rely on the local original project. Even if the original project cannot be compiled successfully during the development process, the code generator of the client 200 can still work normally. In addition, the configuration of code generation follows the project, and each developer does not need to repeat the configuration, which simplifies the configuration process of code generation.
[0042] For example, the above-mentioned permission verification process may be to obtain the client 200 identifier in the code generation request, and perform identity permission verification on the client 200 through the client 200 identifier; wherein, the server 100 may be pre-set with permission ranges for different clients 200, and each client 200 can only initiate service requests within the permission range to the server 100; for example, different clients 200 may be allowed to generate code for different projects.
[0043] In addition, in various stages of the code generation operation process executed by the server 100, permission checks of other types or operations may be performed. The specific permission check rules and the check process may be set accordingly according to actual needs, and this embodiment does not limit this.
[0044] Correspondingly, if Figure 3 As shown, in one example, the client 200 may include the following steps when executing the code generation process: S210, after initiating a code generation request to the server 100, receiving a file package output by the server 100; S220, after decompressing the file package, run the code coverage rules of each code file in the file package to add each code file to the storage path corresponding to the target project according to the coverage method corresponding to the code coverage rule, and obtain executable code.
[0045] If the client 200 needs to create code for a certain project, it will initiate a code generation request for the target project to the server 100, so that the server 100 will generate the corresponding project code based on the target project. After the client 200 receives the code file containing the project code, it will transfer it to the directory path of the target project, thereby completing the coverage of the code logic and the generation of executable code.
[0046] Exemplarily, before initiating a code generation request, the client 200 may pre-configure a code generation plug-in and generate dependency information of the code generation plug-in, and then execute the code generation process through the code generation plug-in. Optionally, the code generation plug-in may be a Maven plug-in.
[0047] Furthermore, the dependency information of the code generation plug-in includes the project parameters of the project to be developed, and the project parameters are used to generate a code generation request; wherein the code generation plug-in is used to respond to the code generation command, generate a code generation request, and execute the above steps S210-S220 to obtain executable code. In addition, the project parameters can only include the project name of the project to be developed, thereby simplifying the configuration to the minimum, thereby reducing the configuration risk and code generation risk.
[0048] It should be noted that the dependency of the Maven plug-in can be completed in the pom file (pom.xml) of the Maven project in the client 200, wherein the dependency information of the Maven plug-in will follow the specific development project, not the integrated development environment (IDE). Thus, the Maven plug-in and the code generation process can be dependent on the IDE or independent of the IDE, and the use of the Maven plug-in is not limited by the IDE and has a wider range of uses.
[0049] Furthermore, after receiving the file package sent by the server 100, the client 200 decompresses the file package, and then obtains and runs the code coverage rules in each code file in turn to implement the code coverage logic, transfers each code file to the corresponding directory path of the target project, and completes the generation of executable code.
[0050] The code coverage rule is used to indicate the coverage method and storage path of the code file; the storage path is the directory path of the target project, and each code file can be added to the directory path according to the storage location index and arrangement order in the file package. The specific settings of the storage path of each code file can be adjusted accordingly according to the needs, and there is no limitation on this.
[0051] Optionally, the code file coverage method includes but is not limited to: 1. Skip (do not process the code file); 2. Skip if there is a local code file of the same type or the same name in the same storage path; 3. Transfer the code file to the corresponding storage path if there is no local code file of the same type or the same name in the same storage path; 4. Delete the local code file if there is a local code file of the same type or the same name in the same storage path, and then transfer the code file to the corresponding storage path. The coverage method corresponding to each code file can be set and adjusted according to the needs, and this embodiment does not limit this.
[0052] Furthermore, the code generation plug-in executes the file coverage logic for each code file in the coverage mode, and then adds each code file to the corresponding storage path according to the storage location index of each code file.
[0053] Exemplarily, the client 200 decompresses the file package, polls each code file in the file package, obtains the code coverage rule of each code file by means such as string recognition, and then loads and executes each rule item in the code coverage rule in each code file to perform code coverage and generation. The code coverage rule of each code file includes multiple rule items, each rule item is used to indicate different executable operations or attribute contents, such as storage path or coverage method, etc.
[0054] It should be noted that the code file generated by the server 100 does not have the ability to run. The code file of the target project can only be truly run and obtain executable code after being integrated into the storage path of the project in the client 200.
[0055] In addition, the code coverage rules can also be used to indicate whether the code files or the generated executable codes can be changed (ie updated), etc.; wherein, the specific code coverage rules can also be set accordingly according to the requirements.
[0056] In one example, if Figure 4 As shown, after obtaining the executable code, the client 200 can initiate a code update instruction according to the demand to update the code according to the instruction, and then the client 200 can perform the following steps: S310, in response to the code update instruction, determining the target code file storing the executable code to be updated indicated in the code update instruction and the code coverage rule of the target code file.
[0057] S320: If it is determined that the code coverage rule indicates that the code can be updated, the corresponding executable code is updated according to the code update instruction.
[0058] S330: If it is determined that the code coverage rule indicates that the code cannot be updated, information that the code cannot be updated is fed back.
[0059] In this embodiment, if the code coverage rule corresponding to the executable code to be updated indicated in the currently initiated code update instruction indicates that the executable code cannot be updated, the client 200 cannot update it. If the code coverage rule indicates that the executable code can be updated, the client 200 can respond to the code update instruction to update the executable code.
[0060] It can be understood that this embodiment uses the code coverage rule to limit the development and modification of the project code by the client 200, thereby improving the security of the project code and making the project code easier to manage. In addition, the development efficiency is significantly improved through automated code generation, especially in large-scale software projects, which can reduce the workload of manually writing repetitive code, while also supporting the ability to quickly iterate and adapt to changes.
[0061] like Figure 5 As shown, the embodiment of the present application also provides a code generation device, which includes: A receiving module 510 is used to receive a code generation request initiated by a client, wherein the code generation request carries project parameters of a project to be developed; An acquisition module 520 is used to determine a project database associated with the project parameters from internally stored project maintenance information according to the project parameters, and acquire table structure data in the project database; the table structure data includes project data and data structure for generating code texts, and generation rules for indicating code templates; A generation module 530, configured to generate a code template based on the generation rule, and to generate a plurality of code files according to the project data, the data structure and the code template; each of the code files includes a code coverage rule; The sending module 540 is used to compress each of the code files into a file package and then send it to the client, so that the client decompresses the file package to run the code coverage rules in each of the code files to obtain the executable code of the target project.
[0062] It can be understood that the code generation device of this embodiment corresponds to the code generation method applied to the server in the above embodiment, and the optional items in the above embodiment are also applicable to this embodiment, so they will not be described repeatedly here.
[0063] like Figure 6 As shown, the embodiment of the present application also provides another code generation device, which includes: The receiving module 610 is used to receive the file package output by the server after initiating a code generation request to the server; The running module 620 is used to run the code coverage rules of each code file in the file package after decompressing the file package, so as to add each code file to the storage path corresponding to the target project according to the coverage method corresponding to the code coverage rule to obtain executable code.
[0064] It can be understood that the code generation device of this embodiment corresponds to the code generation method applied to the client in the above embodiment, and the optional items in the above embodiment are also applicable to this embodiment, so they will not be described repeatedly here.
[0065] An embodiment of the present application also provides an electronic device. Exemplarily, the electronic device includes a processor and a memory, wherein the memory stores a computer program, and the processor executes the above-mentioned code generation method applied to the server 100 or the client 200 by running the computer program.
[0066] Among them, the processor in the above-mentioned electronic device can be an integrated circuit chip with signal processing capabilities. The processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU) and a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or at least one of other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc., which can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of this application.
[0067] The memory in the above electronic device may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), etc. The memory is used to store a computer program, and the processor may execute the computer program accordingly after receiving an execution instruction.
[0068] The present application also provides a computer storage medium for storing the computer program used in the above electronic device. The computer storage medium may be volatile or non-volatile; in addition, the computer readable storage medium may include but is not limited to: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0069] In several embodiments provided in the present application, it should be understood that the disclosed system and method can also be implemented in other ways. The system embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or the flow diagram, and the combination of boxes in the structure diagram and / or the flow diagram, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0070] In addition, the functional modules or units in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0071] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
[0072] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A code generation method, It is characterized in that Applied to the server, including: Receive a code generation request initiated by a client, wherein the code generation request carries project parameters of a project to be developed; According to the project parameters, determine a project database associated with the project parameters from internally stored project maintenance information, and obtain table structure data in the project database; the table structure data includes project data and data structure for generating code texts, and generation rules for indicating code templates; Generate a code template based on the generation rule, and generate a plurality of code files according to the project data, the data structure and the code template; each of the code files contains a code coverage rule; Each of the code files is compressed into a file package and then sent to the client, so that the client decompresses the file package to run the code coverage rules in each of the code files to obtain executable code for the target project.
2. The code generation method according to claim 1, It is characterized in that After receiving the code generation request initiated by the client, the method further includes: Performing a permission check on the client according to the code generation request to determine whether the client has the permission to generate the executable code of the project to be developed; If the permission check is passed, respond to the code generation request and perform a code generation operation; If the permission check fails, a no-authorization-to-operate message is returned to the client.
3. The code generation method according to claim 1, It is characterized in that Before receiving the code generation request initiated by the client, the method further includes: Different projects to be developed and project maintenance information of each of the projects are created, wherein the project maintenance information includes a project name and a project database associated with the project name; the project database includes table structure data, code templates and code coverage rules.
4. A code generation method, It is characterized in that Applied to the client, including: After initiating a code generation request to the server, receiving the file package output by the server; After the file package is decompressed, the code coverage rules of each code file in the file package are run to add each code file to the storage path corresponding to the target project according to the coverage method corresponding to the code coverage rule to obtain executable code.
5. The code generation method according to claim 4, It is characterized in that Before initiating a code generation request to the server, the method further includes: Configure a code generation plug-in and generate dependency information of the code generation plug-in; the dependency information includes project parameters of the project to be developed, and the project parameters are used to generate a code generation request; The code generation plug-in is used to respond to the code generation command, generate a code generation request, and execute the steps of receiving the compressed data packet containing the code file output by the server, decompressing the compressed data packet, and running the code coverage rules in each of the code files to obtain the executable code.
6. The code generation method according to claim 4, It is characterized in that Each of the code files is stored in the file package according to a storage location index, and the code coverage rule of each code file in the file package is run to add each of the code files to the storage path corresponding to the target project according to the coverage method corresponding to the code coverage rule, including: Run the code coverage rules in each of the code files in sequence; the code coverage rules are used to indicate the coverage mode and storage path of the code files; After executing the file overwriting logic according to the overwriting method for each of the code files, the code files are added to the storage path according to the storage location index of each of the code files.
7. The code generation method according to claim 4 or 6, It is characterized in that Also includes: In response to the code update instruction, determining a target code file storing the executable code to be updated indicated in the code update instruction and a code coverage rule for the target code file; If it is determined that the code coverage rule indicates that the code can be updated, then updating the corresponding executable code according to the code update instruction; If it is determined that the code coverage rule indicates that the code cannot be updated, information that the code cannot be updated is fed back.
8. A code generation system, It is characterized in that include: Client, used to initiate code generation request; A server, configured to receive the code generation request, to execute the code generation method according to any one of claims 1 to 3, and to send a file package to the client; The client is also used to receive the file package to execute the code generation method according to any one of claims 4 to 7.
9. An electronic device, It is characterized in that The electronic device comprises a processor and a memory, wherein the memory stores a computer program, and the processor is configured to execute the computer program to implement the code generation method according to any one of claims 1 to 3 or the code generation method according to any one of claims 4 to 7.
10. A computer storage medium, It is characterized in that The computer program stores a computer program, which, when executed on a processor, implements the code generation method according to any one of claims 1 to 3 or the code generation method according to any one of claims 4 to 7.
Citation Information
Patent Citations
Project file generation method and platform
CN108509553A
Code generation method and device, computer equipment and storage medium
CN110147225A
Logistics service code generation method, client, electronic device and system
CN112000319A
Code generation method and device, electronic equipment and storage medium
CN114741070A
Code generation method, device and equipment
CN115712416A
