CN113703755A - Code generation method and code generation device - Google Patents

Code generation method and code generation device Download PDF

Info

Publication number
CN113703755A
CN113703755A CN202110898953.4A CN202110898953A CN113703755A CN 113703755 A CN113703755 A CN 113703755A CN 202110898953 A CN202110898953 A CN 202110898953A CN 113703755 A CN113703755 A CN 113703755A
Authority
CN
China
Prior art keywords
code
target
data source
generation method
field information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110898953.4A
Other languages
Chinese (zh)
Inventor
陈兴吉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Bee Internet Technology Co ltd
Original Assignee
Shenzhen Bee Internet Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Bee Internet Technology Co ltd filed Critical Shenzhen Bee Internet Technology Co ltd
Priority to CN202110898953.4A priority Critical patent/CN113703755A/en
Publication of CN113703755A publication Critical patent/CN113703755A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven
    • G06F8/355Round-trip engineering
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The invention is suitable for the technical field of computers, and provides a code generation method and a code generation device, wherein the code generation method responds to the operation of selecting a data source on a first interface, displays a data table corresponding to the data source on the first interface, responds to the selection operation of the data table, acquires table field information of the selection operation, reads a corresponding code template from a first storage position according to the table field information, updates a target variable in the code template according to the table field information, and finally converts the code template after updating the target variable to obtain a target code. The embodiment of the invention can provide various code templates with variables, after a user selects the corresponding data source and the table field information, the code template can be determined according to the selection result, and the target code can be obtained after the variables in the code template are updated to the table field information, so that the development time is greatly saved, the code style is unified, and the later maintenance is easy.

Description

Code generation method and code generation device
Technical Field
The invention belongs to the technical field of computers, and particularly relates to a code generation method and a code generation device.
Background
The existing code generator can only generate a single table at a time, and can only generate corresponding entity classes and fixed simple classes, which is not flexible enough.
When a plurality of forms need to be generated or different functions need to be realized, software technicians are needed to write related codes, the efficiency is low, and due to the difference of the software technicians, the written codes have different styles and are not easy to maintain later.
Disclosure of Invention
The invention aims to solve the technical problems of providing a code generation method and a code generation device, and aims to solve the problems of troublesome code compiling, low efficiency and difficult later maintenance in the prior art.
The invention is realized in such a way that a code generation method comprises the following steps:
responding to the operation of selecting the data source on the first interface, and displaying a data table corresponding to the data source on the second interface;
responding to the selection operation of the data table, and acquiring table field information of the selection operation;
reading a code template corresponding to the table field information from a first storage position according to the table field information;
updating a target variable in the code template according to the table field information;
and converting the code template after the target variable is updated according to a preset format to obtain a target code.
Further, the code generation method further includes:
creating a plurality of initial templates through a preset generation engine;
setting variable contents in the plurality of initial templates as variable variables to obtain a plurality of code templates;
saving a number of the code templates to the first storage location;
the code templates comprise a front-end code template, a back-end code template and a database script code template.
Further, the preset generation engine is a velocity engine.
Further, the displaying, on the second interface, the data table corresponding to the data source in response to the operation of selecting the data source on the first interface includes:
responding to a data source selection operation, displaying a data source list in the first interface, wherein the data source comprises a plurality of data sources;
responding to the selected operation of a target data source in the data source list, reading the first storage position, and acquiring a data table corresponding to the target data source stored in the first storage position;
and displaying a data table corresponding to the target data source on the second interface, wherein the data table comprises a plurality of table fields, the data table corresponds to a target table database in the first storage position, and the target database stores code templates corresponding to the table fields.
Further, the obtaining table field information of the selection operation in response to the selection operation on the data table comprises:
when the selection operation in the data table is detected, judging whether the selection operation is the selection operation on the table field in the data table;
and if so, acquiring a target table field of the selected operation, and determining table field information by using the name of the target table field, wherein the table field information comprises a field name, a field type and a field description.
Further, the updating the target variable in the code template according to the table field information includes:
and replacing the target variable in the code template with the table field information.
Further, the converting the code template after updating the target variable according to a preset format to obtain the target code includes:
and converting the code template with the target variable replaced into a java file to obtain the target code.
Further, after obtaining the object code, the method further includes:
and compressing the target code to obtain a target code packet, and storing the target code packet to a second storage position.
The embodiment of the present invention further provides a code generation apparatus, which includes a memory, a processor, and a computer program stored in the memory and running on the processor, and when the processor executes the computer program, the steps in the code generation method are implemented.
An embodiment of the present invention further provides a readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the computer program implements the steps in the code generation method as described above.
Compared with the prior art, the invention has the beneficial effects that: the code generation method provided by the embodiment of the invention responds to the operation of selecting a data source on the first interface, displays a data table corresponding to the data source on the first interface, responds to the selection operation of the data table, acquires the table field information of the selection operation, reads a corresponding code template from a first storage position according to the table field information, updates a target variable in the code template according to the table field information, and finally converts the code template after updating the target variable to obtain a target code. The embodiment of the invention can provide various code templates with variables, after a user selects the corresponding data source and the table field information, the code template can be determined according to the selection result, and the target code can be obtained after the variables in the code template are updated to the table field information, so that the development time is greatly saved, the code style is unified, and the later maintenance is easy.
Drawings
FIG. 1 is a flow chart of a code generation method provided by an embodiment of the invention;
fig. 2 is a schematic structural diagram of a code generation apparatus according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The embodiment of the invention discloses a code generation method and a code generation device for generating corresponding codes according to a database table. The code generation method provided by the embodiment of the invention mainly comprises the following steps: the database configuration is stored, different data sources can be selected, a plurality of tables can be selected at one time, packet names can be dynamically appointed, project structures can be dynamically selected, more complex codes can be generated in a self-defined mode according to business requirements, not only can rear-end codes be generated, but also front-end codes, database scripts and the like can be generated. The method is simple and convenient to operate, the codes can be exported by selecting the database table, the codes can be started without being modified and copied into the project, development time is greatly saved, and the code style is unified.
Fig. 1 illustrates a code generation method provided by an embodiment of the present invention, including:
s100, responding to the operation of selecting the data source on the first interface, and displaying the data table corresponding to the data source on the second interface.
Specifically, the method specifically comprises the following steps: responding to a data source selection operation, displaying a data source list in the first interface, wherein the data source comprises a plurality of data sources; responding to the selected operation of a target data source in the data source list, reading the first storage position, and acquiring a data table corresponding to the target data source stored in the first storage position; and displaying a data table corresponding to the target data source on the second interface, wherein the data table comprises a plurality of table fields, the data table corresponds to a target table database in the first storage position, and the target database stores code templates corresponding to the table fields. In this embodiment, if a user triggers a code generation operation through a code generation device (also referred to as a code generator), when starting to generate a target code, a data source selection operation is performed in a related operation interface provided by the code generation device, where the data source selection operation indicates that the user needs to open all data source lists and perform corresponding operations, and therefore, when the data source selection operation of the user is detected, the code generation device displays a first interface and displays a data source list on the first interface, where the data source list includes names of data sources that are preset to be capable of generating the related code. And when a user selects a corresponding data source in the data list displayed on the first interface, the code generation device reads a first storage position by taking the selected data source as a target data source, the first storage position is also called as a database, the database is in one-to-one correspondence with the target data source, and the code generation device acquires a data table corresponding to the target data source in the database and displays the data table in a second interface.
S200, responding to the selection operation of the data table, and acquiring the table field information of the selection operation.
In this step, when a selection operation on the data table is detected, whether the selection operation is a selection operation on a table field in the data table is judged; and if so, acquiring a target table field of the selected operation, and determining table field information by using the name of the target table field, wherein the table field information comprises a field name, a field type and a field description. Specifically, the data table includes a plurality of table fields, each table field is provided with a selection box in front, if the selection box is selected, the table field is selected, and after the selection box in front of the table field is selected, the table field is used as a target table field, and table field information is determined according to the name of the table field. Specifically, the names of each table field are different, and after the table field is selected, the selected table field information is determined according to the name of the table field.
And S300, reading a code template corresponding to the table field information from a first storage position according to the table field information.
In this step, the code generation apparatus reads the code template corresponding to the table field information from the first storage location (i.e., the database) after determining the table field information, and it should be noted that, in this step, the table field information may correspond to a plurality of code templates, and therefore, a plurality of code templates may be read from the first storage location based on the table field information.
And S400, updating the target variable in the code template according to the table field information.
In this step, the target variable in the code template is replaced with the table field information.
And S500, converting the code template after the target variable is updated according to a preset format to obtain a target code.
In this step, the code template with the target variable replaced in step S400 is converted into a java-like file, so as to obtain the target code. Specifically, in the actual application process, after the object code is obtained, the code generation device compresses the object code to obtain an object code packet, stores the object code packet to a second storage location, where the compressed format is a zip format, and after the object code is compressed, generates a zip file and derives a value second storage location.
Before the code generation device performs the code generation method, the method further comprises the step of generating a corresponding code template according to the setting, and the specific steps comprise: creating a plurality of initial templates through a preset generation engine; setting variable contents in the plurality of initial templates as variable variables to obtain a plurality of code templates; saving a number of the code templates to the first storage location; the code templates comprise a front-end code template, a back-end code template and a database script code template. Specifically, the preset generation engine is a velocity engine.
As shown in fig. 2, an embodiment of the present invention further provides a code generation apparatus, which includes a memory, a processor, and a computer program stored in the memory and running on the processor, where the processor executes the computer program to implement the steps in the code generation method as described above.
An embodiment of the present invention further provides a readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the computer program implements the steps in the code generation method as described above.
The following examples further illustrate the invention:
1. the code generation device creates each code template by setting and using a velocity engine, wherein the code template comprises a front-end related file, a rear-end related file, a database script file and the like, and variable contents in each code template are replaced by variable variables;
2. the code generation means determines a connection to the database via the selected data source. The code generation device is provided with a display interface, connection information of a data source can be configured on a first interface, the data source is the connection information of a database, the code is connected with the database through the connection information of the data source, after the first interface selects the corresponding data source, the code generation device jumps to a second interface, and the second interface displays a data table corresponding to the data source.
3. The code generation device determines the selection operation in the data table, and acquires table field information through the selected table field, wherein the table field information comprises a field name, a field type, a field description and the like, the data table corresponds to the related data of the database, and the table field in the data table is selected through selection of the second interface, so that the related code of the selected table field is generated;
4. and dynamically constructing parameter variables according to the table field information, and generating an output file by combining a code template. Specifically, according to the table field information, the corresponding code file is generated according to the predefined code template, the code template in this embodiment is a general code, only some of which are variable parameters, and are referred to as variable variables in this implementation. The generated target code file is that the variable parameters in the code template are replaced by table field information to be generated, the class of java is generated according to the template, and the content is the operations of adding, deleting, modifying and checking the related content in the code template;
5. the generated object code files are stored according to a package name structure, a zip file is generated and exported, the object code files are multiple, the object code is generally layered and comprises a control layer, an entity class, a service layer, a database access layer and the like, and the zip compressed file contains the generated object code.
By the embodiment provided by the invention, a plurality of tables can be selected at one time, the use efficiency is increased, code files required by a plurality of services such as a front end, a back end, a database and the like can be generated, and the workload is greatly reduced.
In the several embodiments provided in the present application, it should be understood that the disclosed method and apparatus may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical division, and other divisions may be realized in practice, for example, a plurality of modules or components may be combined or integrated into another apparatus, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or modules, and may be in an electrical, mechanical or other form.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing module, or each of the modules may exist alone physically, or two or more modules are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode.
The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It should be noted that, for the sake of simplicity, the above-mentioned method embodiments are described as a series of acts or combinations, but those skilled in the art should understand that the present invention is not limited by the described order of acts, as some steps may be performed in other orders or simultaneously according to the present invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no acts or modules are necessarily required of the invention.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In view of the above description of the code generation method and the code generation apparatus provided by the present invention, those skilled in the art will recognize that there are variations in the concepts of the embodiments of the present invention, and that the present disclosure is not limited to the embodiments and the application scope of the present invention.

Claims (10)

1. A code generation method, characterized in that the code generation method comprises:
responding to the operation of selecting the data source on the first interface, and displaying a data table corresponding to the data source on the second interface;
responding to the selection operation of the data table, and acquiring table field information of the selection operation;
reading a code template corresponding to the table field information from a first storage position according to the table field information;
updating a target variable in the code template according to the table field information;
and converting the code template after the target variable is updated according to a preset format to obtain a target code.
2. The code generation method of claim 1, wherein the code generation method further comprises:
creating a plurality of initial templates through a preset generation engine;
setting variable contents in the plurality of initial templates as variable variables to obtain a plurality of code templates;
saving a number of the code templates to the first storage location;
the code templates comprise a front-end code template, a back-end code template and a database script code template.
3. The code generation method of claim 2, wherein the preset generation engine is a velocity engine.
4. The code generation method of claim 1, wherein the displaying a data table corresponding to the data source on a second interface in response to the operation of selecting the data source on the first interface comprises:
responding to a data source selection operation, displaying a data source list in the first interface, wherein the data source comprises a plurality of data sources;
responding to the selected operation of a target data source in the data source list, reading the first storage position, and acquiring a data table corresponding to the target data source stored in the first storage position;
and displaying a data table corresponding to the target data source on the second interface, wherein the data table comprises a plurality of table fields, the data table corresponds to a target table database in the first storage position, and the target database stores code templates corresponding to the table fields.
5. The code generation method of claim 4, wherein the obtaining table field information of a selection operation in response to the selection operation on the data table comprises:
when the selection operation in the data table is detected, judging whether the selection operation is the selection operation on the table field in the data table;
and if so, acquiring a target table field of the selected operation, and determining table field information by using the name of the target table field, wherein the table field information comprises a field name, a field type and a field description.
6. The code generation method of claim 1, wherein said updating target variables in the code template according to the table field information comprises:
and replacing the target variable in the code template with the table field information.
7. The code generation method of claim 6, wherein converting the code template after updating the target variable according to a preset format to obtain the target code comprises:
and converting the code template with the target variable replaced into a java file to obtain the target code.
8. The code generation method of any one of claims 1 to 7, further comprising, after obtaining the object code:
and compressing the target code to obtain a target code packet, and storing the target code packet to a second storage position.
9. A code generation apparatus comprising a memory, a processor and a computer program stored on the memory and running on the processor, wherein the processor implements the steps of the code generation method according to any one of claims 1 to 8 when executing the computer program.
10. A readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the code generation method according to any one of claims 1 to 8.
CN202110898953.4A 2021-08-04 2021-08-04 Code generation method and code generation device Pending CN113703755A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110898953.4A CN113703755A (en) 2021-08-04 2021-08-04 Code generation method and code generation device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110898953.4A CN113703755A (en) 2021-08-04 2021-08-04 Code generation method and code generation device

Publications (1)

Publication Number Publication Date
CN113703755A true CN113703755A (en) 2021-11-26

Family

ID=78652247

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110898953.4A Pending CN113703755A (en) 2021-08-04 2021-08-04 Code generation method and code generation device

Country Status (1)

Country Link
CN (1) CN113703755A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114579112A (en) * 2022-02-25 2022-06-03 北京圣博润高新技术股份有限公司 Method, device, equipment and storage medium for assisting system development
CN117234473A (en) * 2023-08-25 2023-12-15 北京明朝万达科技股份有限公司 Code generation method and device, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080046868A1 (en) * 2006-08-21 2008-02-21 Efstratios Tsantilis Method and system for template-based code generation
US20140317563A1 (en) * 2013-04-22 2014-10-23 John O'Byrne Generate field mapping
CN106873974A (en) * 2016-12-30 2017-06-20 武汉默联股份有限公司 Smart code generates automotive engine system and method
CN109240661A (en) * 2018-08-02 2019-01-18 武汉烽火众智数字技术有限责任公司 A kind of code generating method and device
CN109725891A (en) * 2018-12-29 2019-05-07 深圳市思迪信息技术股份有限公司 The method and device that business module quickly generates

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080046868A1 (en) * 2006-08-21 2008-02-21 Efstratios Tsantilis Method and system for template-based code generation
US20140317563A1 (en) * 2013-04-22 2014-10-23 John O'Byrne Generate field mapping
CN106873974A (en) * 2016-12-30 2017-06-20 武汉默联股份有限公司 Smart code generates automotive engine system and method
CN109240661A (en) * 2018-08-02 2019-01-18 武汉烽火众智数字技术有限责任公司 A kind of code generating method and device
CN109725891A (en) * 2018-12-29 2019-05-07 深圳市思迪信息技术股份有限公司 The method and device that business module quickly generates

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114579112A (en) * 2022-02-25 2022-06-03 北京圣博润高新技术股份有限公司 Method, device, equipment and storage medium for assisting system development
CN114579112B (en) * 2022-02-25 2023-10-20 北京圣博润高新技术股份有限公司 Method, device, equipment and storage medium for assisting system development
CN117234473A (en) * 2023-08-25 2023-12-15 北京明朝万达科技股份有限公司 Code generation method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN115712413B (en) Low code development method, device, equipment and storage medium
CN113703755A (en) Code generation method and code generation device
CN110389832A (en) ZooKeeper container cluster dispositions method, system, equipment and storage medium
CN106407172B (en) A kind of report form generation method based on XML
CN110688145B (en) Android MVP code automatic generation method and device, medium and electronic equipment
CN114048415A (en) Form generation method and device, electronic equipment and computer readable storage medium
CN113568614A (en) Task issuing method, electronic device and storage medium
CN107220044B (en) Method and device for driving business object based on meta-model
CN110764864A (en) Terraform-based visual resource arrangement method
CN116028062A (en) Target code generation method, NPU instruction display method and device
CN112306622A (en) VNF template construction method and device
CN116048609A (en) Configuration file updating method, device, computer equipment and storage medium
CN114816408A (en) Information processing method and device
CN111124386B (en) Animation event processing method, device, equipment and storage medium based on Unity
CN113377368A (en) Project development method, device, server and storage medium
CN113805850A (en) Artificial intelligence management system based on multiple deep learning and machine learning frameworks
CN113296759A (en) User interface processing method, user interface processing system, user interface processing device, and storage medium
CN112882698A (en) Development environment generation method and device, computer storage medium and electronic device
CN112130841B (en) SQL development method and device and terminal equipment
CN116611418B (en) Report processing method and device based on online editing, electronic equipment and medium
CN113835694B (en) Visual display platform of custom data
CN117453713A (en) SQL sentence generation method, device and storage medium for multi-type database
CN116680006A (en) Model conversion method, device and storage medium
JP2023000689A (en) Input information file generation device, input information file production method, program, and recording medium
CN115509513A (en) GRPC service layer code generation method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination