A method and device for generating code files

By receiving multiple data source files and using preset templates to generate code files, the problem that Mybatis code generator can only generate database type files is solved, and the automation generation of multiple code files is achieved, which improves the development efficiency and saving of software projects. Labor costs.

CN110134427BActive Publication Date: 2024-12-24BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN201810128211.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-02-08
Publication Date
2024-12-24
Estimated Expiration
2038-02-08

AI Technical Summary

Technical Problem

In the prior art, the Mybatis code generator can only generate database-type code files, and other types of code such as pages and scripts need to be written manually, resulting in inefficient code compilation work in software projects.

Method used

By receiving multiple data source files, using preset templates to generate corresponding memory objects, and calling attribute files to convert memory objects into code files, supporting multiple data sources such as Excel and database type files, including entity configuration, interface configuration, and database Connect to configuration and other templates.

Benefits of technology

It realizes automatic generation of multiple code files, shortens the development cycle, saves manual writing costs, and improves the code generation efficiency of software projects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110134427B_ABST
    Figure CN110134427B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for generating a code file, and relates to the field of computer technology. A specific implementation of the method includes: receiving a data source file; entering the data source file into a corresponding preset template to generate a corresponding memory object; calling a property file to convert the memory object into a corresponding code file, wherein the property file is used to save information for configuring the code file. This implementation can save time and labor costs for compiling code files, and generate multiple code files using preset templates.
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 method, device, electronic device and computer-readable medium for generating a code file. Background Art

[0002] With the development of Internet technology, in order to meet the needs of various businesses, there are more and more software projects, the complexity of software projects is getting higher and higher, and the scale of single software projects is gradually increasing. Code compilation of software projects that only rely on manual work can no longer meet the quality and efficiency requirements of software projects.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] In the prior art, Mybatis-Generator (a code generator based on Mybatis, which is a Java persistence layer framework that supports common structured query language SQL queries, stored procedures and advanced mapping) can be used to generate the code for the database tables supported by Mybatis. The data source file can only be a database type file, and other codes such as pages and scripts still need to be written manually. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a code file generation method and device, which can use multiple data sources to generate corresponding various code files by calling various preset templates, shorten the cycle, and save development time and cost.

[0006] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a method for generating a code file is provided, comprising: receiving a data source file; entering the data source file into a corresponding preset template to generate a corresponding memory object; calling a property file to convert the memory object into a corresponding code file, wherein the property file is used to save information for configuring the code file.

[0007] Optionally, before calling the property file to convert the memory object into a corresponding code file, the method further includes: receiving property parameters, converting the property parameters into a property file, wherein the property file includes a project property file, a module property file, an entity property file, a class property file, and an interface property file.

[0008] Optionally, when the data source file is an Excel type file, its corresponding preset templates include: an entity configuration template, an interface configuration template, an enumeration configuration template, and a data transmission object configuration template.

[0009] Optionally, when the data source file is a database type file, its corresponding preset templates include: a database connection configuration template, a library configuration template, and a table configuration template.

[0010] To achieve the above-mentioned purpose, according to another aspect of an embodiment of the present invention, there is provided a device for generating a code file, comprising: a receiving module for receiving a data source file; a template module for entering the data source file into a corresponding preset template to generate a corresponding memory object; and a generating module for calling a property file to convert the memory object into a corresponding code file, wherein the property file is used to save information for configuring the code file.

[0011] Optionally, the device also includes: a property module, which is used to receive property parameters and convert the property parameters into property files before the generation module calls the property file to convert the memory object into a corresponding code file, wherein the property files include project property files, module property files, entity property files, class property files, and interface property files.

[0012] Optionally, when the data source file is an Excel type file, its corresponding preset templates include: an entity configuration template, an interface configuration template, an enumeration configuration template, and a data transmission object configuration template.

[0013] Optionally, when the data source file is a database type file, its corresponding preset templates include: a database connection configuration template, a library configuration template, and a table configuration template.

[0014] To achieve the above-mentioned purpose, according to another aspect of an embodiment of the present invention, there is provided an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement any of the methods described in a method for generating a code file.

[0015] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by one or more processors, any method described in a method for generating a code file is implemented.

[0016] An embodiment of the above invention has the following advantages or beneficial effects: because it adopts the technical means of using multiple preset templates to generate multiple code files, it overcomes the technical problem of the existing method of intelligently generating code files supported by Mybatis, thereby achieving the technical effect of saving time and labor costs for compiling code files.

[0017] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0019] Figure 1 is a schematic diagram of main steps of a method for generating a code file according to an embodiment of the present invention;

[0020] Figure 2 is a schematic diagram of the main parts of a device for generating a code file according to an embodiment of the present invention;

[0021] Figure 3 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0022] Figure 4 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0023] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0024] Figure 1 is a schematic diagram of the main steps of a method for generating a code file according to an embodiment of the present invention, such as Figure 1 As shown:

[0025] Step S101 represents receiving a data source file, wherein the data source file includes an Excel (one of Microsoft Office software) type file or a database type file. The purpose of this step is to generate different code files according to different data source files.

[0026] A preferred implementation of an embodiment of the present invention can be implemented through IntelliJ IDEA. IntelliJ IDEA is an integrated environment developed based on the Java language, which is applied to intelligent code assistants, automatic code prompts, refactoring, code review, graphical user interface GUI design, etc., and provides a rich visual graphical interface framework. The visual interface is implemented through the interface of its custom plug-in.

[0027] Before receiving the data source file, the method further includes: creating an empty Maven (Maven is an open source project management tool written in pure Java) project to perform software project management on the process of generating codes.

[0028] Step S102 indicates entering the data source file into the corresponding preset template to generate the corresponding memory object, wherein the preset template may include a class template, a configuration file template, a page template, a script template, a structured query language template, and a custom template; the purpose of this step is to realize code generation through the preset template, saving labor costs and improving efficiency. The class template is used to generate a class code file, the script template is used to generate a script code file, the page template is used to generate a page code file, the structured query language template is used to generate a structured query language code file, and the custom template is used to generate a custom code file, which is extensible.

[0029] When the data source file is an Excel file, the corresponding preset templates include: entity configuration template, interface configuration template, enumeration configuration template, and data transfer object configuration template. If the Excel data source file is entered according to the above templates, the IntelliJ IDEA plug-in reads the entered file, generates a memory object, and generates a property file that can be recognized by the property editor.

[0030] When the data source file is a database type file, its corresponding preset templates include: database connection configuration template, library configuration template, table configuration template. If the data source file of the database type is entered according to the above templates, the IntelliJ IDEA plug-in reads the entered file, generates a memory object, and generates a property file that can be recognized by the property editor.

[0031] Step S103 indicates calling a property file to convert the memory object into a corresponding code file, wherein the property file is used to store information for configuring the code file.

[0032] Before converting the memory object into a code file according to the corresponding property file, the method further includes: receiving property parameters, and using a visual property editor to convert the property parameters into a corresponding property file, wherein the property file includes: a project property file, a module property file, an entity property file, a class property file, and an interface property file. Among them, the property parameters can also be directly received in the form of a ready-made property file. The project property file is used to configure various property parameters of the project; the module property file is used to configure various property parameters of the module, such as the module name, package name, public component name, etc.; the entity property file is used to configure various property parameters of the entity data; the class property file is used to configure various property parameters of the class file, such as the class name; the interface property file is used to configure various property parameters of the interface file. For example, in IntelliJIDEA, a visual property editor is used to receive various property parameters, and then converted into corresponding property files.

[0033] After generating various code files, these code files are integrated to obtain the code files of the entire software project.

[0034] Figure 2 2 is a schematic diagram of the main parts of a device 200 for generating a code file according to an embodiment of the present invention. Figure 2 As shown:

[0035] The receiving module 201 is used to receive a data source file; wherein the data source file includes an Excel (one of Microsoft office software) type file or a database type file, the purpose of which is to generate different code files according to different data source files.

[0036] A preferred implementation of an embodiment of the present invention can be implemented through IntelliJ IDEA. IntelliJ IDEA is an integrated environment developed based on the Java language, which is applied to intelligent code assistants, automatic code prompts, refactoring, code review, graphical user interface GUI design, etc., and provides a rich visual graphical interface framework. The visual interface is implemented through the interface of its custom plug-in.

[0037] Before receiving the data source file, you can also create an empty Maven (Maven is an open source project management tool written in pure Java) project to perform software project management on the process of generating code.

[0038] The template module 202 is used to enter the data source file into the corresponding preset template to generate the corresponding memory object; wherein the preset template may include a class template, a configuration file template, a page template, a script template, a structured query language template, and a custom template; the purpose is to realize code generation through the preset template, saving labor costs and improving efficiency. Among them, the class template is used to generate a class code file, the script template is used to generate a script code file, the page template is used to generate a page code file, the structured query language template is used to generate a structured query language code file, and the custom template is used to generate a custom code file, which is extensible.

[0039] When the data source file is an Excel file, the corresponding preset templates include: entity configuration template, interface configuration template, enumeration configuration template, and data transfer object configuration template. If the Excel data source file is entered according to the above templates, the IntelliJ IDEA plug-in reads the entered file, generates a memory object, and generates a property file that can be recognized by the property editor.

[0040] When the data source file is a database type file, its corresponding preset templates include: database connection configuration template, library configuration template, table configuration template. If the data source file of the database type is entered according to the above templates, the IntelliJ IDEA plug-in reads the entered file, generates a memory object, and generates a property file that can be recognized by the property editor.

[0041] The generating module 203 is used to call the property file to convert the memory object into a corresponding code file, wherein the property file is used to store information for configuring the code file.

[0042] The device 200 may also include: a property module, which is used to receive property parameters and convert the property parameters into property files before the generation module calls the property file to convert the memory object into the corresponding code file, wherein the property files include project property files, module property files, entity property files, class property files, and interface property files. Among them, the property parameters can also be directly received in the form of ready-made property files. The project property file is used to configure various property parameters of the project; the module property file is used to configure various property parameters of the module, such as module name, package name, public component name, etc.; the entity property file is used to configure various property parameters of entity data; the class property file is used to configure various property parameters of the class file, such as class name; the interface property file is used to configure various property parameters of the interface file. For example, in IntelliJIDEA, a visual property editor is used to receive various property parameters and then convert them into corresponding property files.

[0043] After generating various code files, these code files are integrated to obtain the code files of the entire software project.

[0044] Figure 3 An exemplary system architecture 300 is shown to which a method for generating a code file or an apparatus for generating a code file according to an embodiment of the present invention can be applied.

[0045] like Figure 3 As shown, the system architecture 300 may include terminal devices 301, 302, 303, a network 304 and a server 305. The network 304 is used to provide a medium for communication links between the terminal devices 301, 302, 303 and the server 305. The network 304 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0046] Users can use terminal devices 301, 302, 303 to interact with server 305 through network 304 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 301, 302, 303, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0047] The terminal devices 301 , 302 , and 303 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.

[0048] The server 305 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using the terminal devices 301, 302, and 303. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information and product information) to the terminal device.

[0049] It should be noted that the method for generating a code file provided in the embodiment of the present invention is generally executed by the server 305 , and accordingly, a device for generating a code file is generally disposed in the server 305 .

[0050] It should be understood that Figure 3 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0051] Figure 4 The diagram shown is a schematic diagram of the structure of a computer system 400 of a terminal device suitable for implementing an embodiment of the present invention. Figure 4 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0052] like Figure 4 As shown, the computer system 400 includes a central processing unit (CPU) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage part 408 into a random access memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the system 400 are also stored. The CPU 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0053] The following components are connected to the I / O interface 405: an input section 406 including a keyboard, a mouse, etc.; an output section 407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 408 including a hard disk, etc.; and a communication section 409 including a network interface card such as a LAN card, a modem, etc. The communication section 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the I / O interface 405 as needed. A removable medium 411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 410 as needed, so that a computer program read therefrom is installed into the storage section 408 as needed.

[0054] In particular, according to the embodiments disclosed in the present invention, the process described in the above step diagram can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the step diagram. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 409, and / or installed from the removable medium 411. When the computer program is executed by the central processing unit (CPU) 401, the above-mentioned functions defined in the system of the present invention are executed.

[0055] It should be noted that the computer-readable medium shown in the present invention includes a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two. Computer-readable storage media include, but are not limited to, electrical, magnetic, optical, electromagnetic, infrared, semiconductor systems, devices or devices, or any combination of the above. Computer-readable storage media specifically include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any combination of the above. In the present invention, a computer-readable storage medium includes any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device or device; a computer-readable signal medium includes a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code, and such a propagated data signal can take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any combination of the above signals. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF (radio frequency), etc., or any combination of the above media.

[0056] The step diagram or block diagram in the accompanying drawings illustrates the possible implementation architecture, functions and operations of the system, method and computer program product according to various embodiments of the present invention. Each box in the step diagram or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for implementing the specified logical function. It should be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed in parallel, and sometimes they can be executed in the opposite order, and the execution order depends on the functions involved. It should also be noted that each box in the block diagram or step diagram and its combination can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0057] The modules or units involved in the embodiments of the present invention may be implemented by software or hardware. The modules or units described may also be set in a processor. For example, they may be described as: a processor includes a receiving module, a template module, and a generating module. The names of these modules or units do not, in some cases, constitute limitations on the modules or units themselves. For example, the receiving module may also be described as a "module for receiving a data source file."

[0058] On the other hand, an embodiment of the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: receiving a data source file; entering the data source file into a corresponding preset template to generate a corresponding memory object; calling a property file to convert the memory object into a corresponding code file, wherein the property file is used to save information for configuring the code file.

[0059] According to the technical solution of the embodiment of the present invention, a technical means of using multiple preset templates to generate multiple code files is adopted, thereby overcoming the technical problem of the existing method of intelligently generating code files supported by Mybatis, thereby achieving the technical effect of saving time and labor costs for compiling code files.

[0060] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for generating a code file, characterized in that: Implemented based on IntelliJ IDEA, including: Receive a data source file; the data source file includes an Excel type file or a database type file; Enter the data source file into the corresponding preset template to generate the corresponding memory object; when the data source file is an Excel type file, the corresponding preset templates include: entity configuration template, interface configuration template, enumeration configuration template, data transmission object configuration template; when the data source file is a database type file, the corresponding preset templates include: database connection configuration template, library configuration template, table configuration template; Receive property parameters, and use a visual property editor to convert the property parameters into property files, wherein the property files include project property files, module property files, entity property files, class property files, and interface property files; The property file is called to convert the memory object into a corresponding code file, wherein the property file is used to store information for configuring the code file.

2. A device for generating a code file, characterized in that: include: A receiving module, used for receiving a data source file; The data source file includes an Excel type file or a database type file; The template module is used to input the data source file into the corresponding preset template and generate the corresponding memory object; When the data source file is an Excel type file, the corresponding preset templates include: entity configuration template, interface configuration template, enumeration configuration template, data transmission object configuration template; when the data source file is a database type file, the corresponding preset templates include: database connection configuration template, library configuration template, table configuration template; The property module is used to receive property parameters and convert the property parameters into property files using a visual property editor, wherein the property files include project property files, module property files, entity property files, class property files, and interface property files; A generation module is used to call a property file to convert the memory object into a corresponding code file, wherein the property file is used to store information for configuring the code file.

3. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method as claimed in claim 1.

4. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by one or more processors, the method as claimed in claim 1 is implemented.

Citation Information

Patent Citations

  • Code automatic generation method and device

    CN103135976A

  • Code generation method based on Eclipse platform

    CN105354072A

  • Code generation method and apparatus

    CN106293664A

  • Code generating method and code generating device

    CN106469064A

  • Code automatic generation method and apparatus

    CN106648690A