CN109885291A - A kind of code automatic generation method and code generator - Google Patents

A kind of code automatic generation method and code generator Download PDF

Info

Publication number
CN109885291A
CN109885291A CN201910075242.XA CN201910075242A CN109885291A CN 109885291 A CN109885291 A CN 109885291A CN 201910075242 A CN201910075242 A CN 201910075242A CN 109885291 A CN109885291 A CN 109885291A
Authority
CN
China
Prior art keywords
database
template
interface
code
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
CN201910075242.XA
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 Launch Technology Co Ltd
Original Assignee
Shenzhen Launch 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 Launch Technology Co Ltd filed Critical Shenzhen Launch Technology Co Ltd
Priority to CN201910075242.XA priority Critical patent/CN109885291A/en
Publication of CN109885291A publication Critical patent/CN109885291A/en
Pending legal-status Critical Current

Links

Landscapes

  • Stored Programmes (AREA)

Abstract

This application discloses a kind of code automatic generation method and code generators.This method comprises: receiving the selection instruction of database;The connection configuration of target database is obtained according to the selection instruction;It is configured according to the connection of the target database, connects the target database;Obtain the information of the database table in the target database;Obtain the template for generating code;Obtain interface configurations;According to the interface configurations, configuration interface;And template engine is run on the interface, according to the information of the database table and the template generation code file.Also disclose corresponding device.Using the scheme of the application, it can be according to the connection configuration of the database of preservation and interface configurations, information is obtained from database table, utilize template automatic code generating, relatively easily learnt using the template engine template grammar of open source, it is also easy to extend, does not limit the programming language for generating code, do not limit technology.

Description

A kind of code automatic generation method and code generator
Technical field
This application involves computer field more particularly to a kind of code automatic generation methods and code generator.
Background technique
Having many codes in the development process of software code all is that tactic pattern is similar, we are defined as it Repeated code.Generally there are model class, interface class, service class, data access class, the code of these types is attribute word mostly Section is different, and method name is different, but tactic pattern is similar.Programmer is when developing these codes, often It copies the code having been carried out and then is modified to realize new function.The process of this copy modification is comparatively laborious , and it is easy error, in addition the coding habit of distinct program person is also not quite similar, and it is good that co-development will also result in code spice Green bristlegrass is uneven, is unfavorable for the maintenance of code in this way.Code generator can solve problem above, it can be significantly as a tool Increase the code development efficiency of programmer.There are many intimate code generators on network, wherein more representational There are soft code generator, Database2Sharp, EasyCode.
Although the code generator on network is many, all come with some shortcomings.Such as charge, copyright, technology limiting, volume Cheng Yuyan limit, be unfavorable for extension etc..Code generator belongs to the tool for comparing and being partial to customize, it is also difficult to accomplish that face face is all It arrives, less there is an a possibility that tool solves all problems.It is all that personal customization is right mostly with regard to current code generator Issue on network afterwards, product-level tool be also it is fewer, obtain difficulty it is bigger.Slightly more handy code Generator will all charge, such as Database2Sharp, EasyCode.It moves soft code generator to be free of charge, but also has a little Advertisement.
Moving soft code generator is comprehensive expression of person, and source code is disclosed (non-open source), and tool can be used freely, and function is complete Face, extended capability are strong, and disadvantage is seldom.The slightly template that unfortunately it uses the instruction of the asp.net page to realize, does not connect The learning difficulty touched is big, in addition the less component that its official website must also be gone to understand customized interface method, provided of data Expansion interface also has similar problems.If not changing template, the code fixation generated is three-decker, may with it is existing Code is incompatible.The advantages of Database2Sharp and EasyCode is that interface can be generated, and also results in technology limiting in this way, The dll of its offer must be quoted, these dll are the third party's component do not increased income or charged mostly.In addition the two tools Scalability be also it is poor, they do not provide expansion interface or edit model interface, and the programming language for generating code also limits In C#.
Based on this, the application provides a kind of Code automatic build scheme grasped by force, easily without technology limiting, scalability.
Summary of the invention
The application provides a kind of code automatic generation method and code generator, to solve having in code building Technology limiting, programming language limit, are unfavorable for the problem of extension.
In a first aspect, providing a kind of code automatic generation method, which comprises the selection for receiving database refers to It enables;The connection configuration of target database is obtained according to the selection instruction;It is configured according to the connection of the target database, connection The target database;Obtain the information of the database table in the target database;Obtain the template for generating code;Obtain boundary Face configuration;According to the interface configurations, configuration interface;And template engine is run on the interface, according to the database The information of table and the template generation code file.
In one implementation, the method also includes: receive connection database information;The information is filled into In the data model of the database;Splice to obtain connection string using the information being filled into the data model;Test The database connection;And the connection configuration of the storage database.
In another implementation, the connection configuration of the storage database, comprising: by the company of the database Configuration is connect to be serialized;And the connection configuration of the database after the storage serializing, wherein database The connection configuration of the corresponding database of type.
In another implementation, the method also includes: the interface configurations of user are received, the interface configurations include It is following one or more information: type of database, whether automatic loading of databases table, project name, tester;By the boundary Face configuration sequence;And the interface configurations after the storage serializing.
It is described to run template engine on the interface in another implementation, according to the letter of the database table Breath and the template generation code file, comprising: run template engine on the interface, utilize the number in the database table It is believed that data source of the breath as the template, utilizes the template generation code file.
In another implementation, the method also includes: according to customized table name, obtain database table;It will look into The column name of the database table found is packaged into model object;The model object is rendered on customized name window; The modification to the column name is received on the customized name window;And save modified model object.
It is described to run template engine on the interface in another implementation, according to the letter of the database table Breath and the template generation code file, comprising: run template engine on the interface, utilize the table name in the database Data source with column name as the module utilizes the template generation code file.
Second aspect, provides a kind of code generator, and the code generator includes: the first reception list Member, for receiving data selection instruction in library;First acquisition unit, for obtaining target database according to the selection instruction Connection configuration;Connection unit connects the target database for configuring according to the connection of the target database;Second obtains Unit is taken, for obtaining the information of the database table in the target database;Third acquiring unit generates code for obtaining Template;4th acquiring unit, for obtaining interface configurations;Configuration unit, for according to the interface configurations, configuration interface; And generation unit, it is raw according to the information of the database table and the template for running template engine on the interface At code file.
In one implementation, the code generator further include: the second receiving unit, for receiving connection number According to the information in library;Fills unit, for the information to be filled into the data model of the database;Concatenation unit is used for Splice to obtain connection string using the information being filled into the data model;Test cell, for testing the database Connection;And first storage unit, the connection for storing the database configure.
In another implementation, first storage unit is used to the connection configuration of the database carrying out sequence Change;And the connection configuration of the database after the storage serializing, wherein the corresponding number of the type of a database It is configured according to the connection in library.
In another implementation, the code generator further include: third receiving unit, for receiving user Interface configurations, the interface configurations include following one or more information: type of database, whether automatic loading of databases Table, project name, tester;The interface configurations are serialized;And second storage unit, for storing the serializing Interface configurations afterwards.
In another implementation, the generation unit is for running template engine on the interface, using described Data source of the data information as the template in database table, utilizes the template generation code file.
In another implementation, the code generator further include: the 5th acquiring unit is made by oneself for basis The table name of justice obtains database table;Encapsulation unit, for the column name of the database table found to be packaged into model pair As;Rendering unit, for the model object to be rendered into customized name window;Unit is modified, for making by oneself described The modification to the column name is received on justice name window;And storage unit, for saving modified model object.
In another implementation, the generation unit is for running template engine on the interface, using described The data source of table name and column name as the module in database, utilizes the template generation code file.
The third aspect provides a kind of code generator, including processor, input equipment, output equipment and storage Device, wherein the memory is for storing computer program, and the computer program includes program instruction, the processor quilt It is configured to call described program instruction, executes method described in above-mentioned first aspect.
Fourth aspect provides a kind of computer readable storage medium, is stored in the computer readable storage medium Instruction, when run on a computer, so that computer executes method described in above-mentioned first aspect.
5th aspect, provides a kind of computer program product comprising instruction, when run on a computer, so that Computer executes method described in above-mentioned first aspect.
Using the code automated process and code generator of the application, can be matched according to the connection of the database of preservation It sets and interface configurations, information is obtained from database table, using template automatic code generating, using the template engine of open source, mould Plate grammer relatively easily learns, and is also easy to extend, and does not limit the programming language for generating code, does not limit technology.
Detailed description of the invention
Fig. 1 is a kind of configuration diagram of code generator provided by the embodiments of the present application;
Fig. 2 is a kind of flow diagram of code automatic generation method provided by the embodiments of the present application;
Fig. 3 is the connection configuration flow signal of database during a kind of Code automatic build provided by the embodiments of the present application Figure;
Fig. 4 is the flow diagram of interface configurations during a kind of Code automatic build provided by the embodiments of the present application;
Fig. 5 is the loaded and displayed process signal of data source during a kind of Code automatic build provided by the embodiments of the present application Figure;
Fig. 6 be customized table name during a kind of Code automatic build provided by the embodiments of the present application, column name process show It is intended to;
Fig. 7 is a kind of modular structure schematic diagram of code generator provided by the embodiments of the present application;
Fig. 8 is a kind of hardware structural diagram of code generator provided by the embodiments of the present application.
Specific embodiment
The embodiment of the present application is described below with reference to the attached drawing in the embodiment of the present application.
Fig. 1 is a kind of configuration diagram of code generator provided by the embodiments of the present application.Database be code from The data source of dynamic generator, the compatibility of multiple database is realized by unified interface.Database table information includes table name, column Name, table data.Database may include one or more database tables, and each database table has table name;Each database table It may include one or more columns per page, each column have column name;Each database table may include 0 row, 1 row or multirow.Database can To include various database types, such as Sqlserver, MySQL, SQLite, Oracle, PostgreSql and DB2 etc..Code Automatic generator is mainly made of two big functional modules: " generating from database " and " from template generation " functional module.From data Library generate the functional module mainly realize using in database table table name and column name information as the data source of template engine, then tie Built-in template is closed, generates code file using NVelocity engine.Built-in template is stored in~Template default Under catalogue, template suffix be .vm, can pass through production new template and copy to the catalogue achieve the purpose that extend the functions of modules. Mainly realize that the data information inside using database table as the data source of template engine, then is tied from the template generation functional module Shuttering or editing template generate code using NVelocity engine.The function is more flexible, and opposite also has user of service Higher requirement, user of service need to grasp VTL language.Configuration file is mainly database of record connection and interface configurations, purpose It is that reduction is unnecessary to repeatedly input, promotes user experience.
A kind of code automatic generation method and code generator provided by the embodiments of the present application, can be according to preservation The connection configuration of database and interface configurations, obtain information from database table, using template automatic code generating, using open source Template engine, template grammar relatively easily learns, is also easy to extend, and does not limit the programming language for generating code, does not limit skill Art.
It should be noted that " multiple " refer to two or more in the embodiment of the present application, in consideration of it, the application is real " at least two " can also be interpreted as " multiple " by applying in example."and/or", describes the incidence relation of affiliated partner, and expression can be with There are three kinds of relationships, for example, A and/or B, can indicate: individualism A exists simultaneously A and B, these three feelings of individualism B Condition.In addition, character "/" typicallys represent the relationship that forward-backward correlation object is a kind of "or" unless otherwise specified.
Fig. 2 is a kind of flow diagram of code automatic generation method provided by the embodiments of the present application.Wherein:
S101, the selection instruction for receiving database.
As shown in Figure 1, database has multiple types, user can send selection instruction, generation to code generator Code automatic generator receives the selection instruction, selects a kind of selected type of database of the selection instruction.
S102, the connection that target database is obtained according to the selection instruction configure.
S103, it is configured according to the connection of the target database, connects the target database.
The code generator of the present embodiment can connect the database of multiple types.It can be according to preparatory database Connection configuration, connection user selection any type of target database.Connection configuration includes title, default value, setting class Type, whether show, file filter device, whether can the items such as sky.Specifically, the connection configuration of database can be with binary sequence Column are stored in configuration file, for example, file be stored in~under ConnStrConfig catalogue, each type of database corresponding one A configuration file.
S104, the information for obtaining database table in the target database.
Database is the data source of code generator, and the compatibility of multiple database is realized by unified interface.Number It include table name, column name, table data according to library table information.Database may include one or more database tables, each database table With table name;Each database table may include one or more columns per page, and each column have column name;Each database table may include 0 Row, 1 row or multirow.
The code generator of the application has " generating from database " and " from template generation " two functional modules.It obtains The information of database table in database, can be using in database table table name and column name information as the data of template engine Source is also possible to the data information inside using database table as the data source of template engine.
S105, the template for generating code is obtained.
The template for generating code can be obtained by selecting a template or editing out a template.
Because generating code using the mode of template, it is not only restricted to generate the programming language of code, to journey The code of any programming language is all text-string for sequence.
S106, interface configurations are obtained.
The interface configurations, which can be, to be pre-configured with and saves.Obtain the interface configurations of the serializing of storage.
S107, according to the interface configurations, configuration interface.
According to the interface configurations of acquisition, configuration interface, and the interface configurations are exported, so as in automatic code generating mistake It is shown and is inputted by the interface in journey.
S108, template engine is run on the interface, according to the information of the database table and the template generation generation Code file.
Template engine is run, the information for the database table that can be will acquire is written in template, generates code file.
Specifically, for example, using in database table table name and column name information as the data source of template engine, run template Engine, so that it may obtain the table name and the corresponding data information of column name generates corresponding code file.It can be according in a table The corresponding data information of multiple column generate code file.
Specifically, it in another example, using the data information inside database table as the data source of template engine, runs template and draws It holds up, so that it may which corresponding code file is generated according to the data information of a table.
It, can be according to the connection of the database of preservation according to a kind of code automatic generation method provided by the embodiments of the present application Configuration and interface configurations, obtain information from database table, using template automatic code generating, using the template engine of open source, Template grammar relatively easily learns, and is also easy to extend, and does not limit the programming language for generating code, and programming language refers to Java/ C#/VB/Html/Js/Python etc. does not limit technology.
For embodiment shown in Fig. 2, in one embodiment, the also connection configuration of progress database.Specifically, as schemed It further includes following steps before S101 that database shown in 3, which connects configuration flow schematic diagram:
S201, the information for receiving connection database.
User can input connection database by the window of the configuration database link information of code generator Information.For example, sqlite will input Data Source, Version, Password.The major function of the window is editor, surveys It tries configuration information and saves database linkage information.It uses pouring-in window design, and a forms can complete all numbers The configuration connected according to library.In the existing solution, how many type of database how many kinds of is just write specifically in fact using Existing, the application is only compatible with all databases with a kind of realization.Unified database interface definition, defines database manipulation and connects Mouth and Database Schema Information obtain interface.
S202, the information is filled into the data model of the database.
There are many type, the models of corresponding multiple databases for database.According to the type of database that user selects, program is certainly The dynamic data model for determining database to be used.
By taking sqlite as an example, its model is as follows:
Then, the information for connecting database is filled into the model of database, can be reflected and is obtained by the model of injection It is derived from defined property, to obtain type of database and connection setting.Connection setting includes title, default value, setting type, is No display, file filter device, whether can the items such as sky.Corresponding control is dynamically rendered on forms using information above, is reached certainly Adapt to the effect of database connection configuration.
S203, splice to obtain connection string using the information being filled into the model.
Splice to obtain connection string using the information being filled into the model, thus real using the connection string The connection of exampleization database.
S204, the test database connection proceed to next step S205 if test passes through;Otherwise, it goes to S201。
S205, the connection configuration of the database is serialized.
The connection configuration of the database after S206, the storage serializing, wherein the type of a database is corresponding The connection configuration of one database.
Wherein, S205 and S206 is the connection configuration for storing the database, i.e. preservation database connection is configured to configuration File.Specifically, database catenation sequence is the process that database connection is saved and read.The data model of injection is populated After the setting of user configuration, which will be stored, when being again introduced into database connection configuration so as to next user It is loaded directly into default value, user can be thus reduced and repeatedly input.Here Model sequence uses binary system sequence Columnization, file is stored in~under ConnStrConfig catalogue, the corresponding configuration file of each type of database.
For embodiment shown in Fig. 2, in another embodiment, the configuration at interface is also carried out.Specifically, such as Fig. 4 institute Show, further include following steps before S101:
S301, the interface configurations for receiving user.
User input interface can configure on the interface of code generator.The interface configurations include with next Or multiple information: type of database, whether automatic loading of databases table, project name, tester.These information will save Come, default value is loaded directly into when being again introduced into the interface so as to next user, it is defeated can thus to reduce user's repetition Enter.
S302, the interface configurations are serialized.
Interface configurations serializing is the process that the essential information that user inputs on interface is saved and read.Here model Serializing use XML serialization, from database generate interface configuration file be stored in~DatabaseConfig In Config.xml, be stored in from the interface configurations of template generation~TemplateConfig in Config.xml.
Interface configurations after S303, the storage serializing.
For embodiment shown in Fig. 2, In yet another embodiment, after S102, further include data source load it is aobvious Show.Data source loaded and displayed is the database connection connection database by user configuration, all data in reading database Library table is simultaneously shown to interface control.Specifically, as shown in figure 5, further including following steps after S102 and before S103:
Template directory built in S401, inspection.The template directory is created that template directory if it does not exist.
Template list built in S402, reading.
Control built in S403, display on template list to interface.
Wherein, S402 and S403 is then not present if it is from template generation code in code generator.
S404, interface configuration file Config.xml is read.If reading the interface configuration file, proceed to S405;If this document is not present with regard to default initialization, end process.
S405, unserializing interface configuration file.
Specifically, XML unserializing Config.xml is data model.
S406, the value filling interface edit control with model.
S407, judge whether to load with ' whether automatic loading of databases table ' in model.If load, proceeds to S408;Interface loading procedure terminates if not loading automatically.
S408, judge that database connection profile whether there is.If it is present proceeding to S409;If there is no Then interface loading procedure terminates.
S409, binary system unserializing database connection profile are data model.
S410, database linkage information is obtained from model, and initialize connection example, connect database.If obtained It is connected to database, then proceeds to S411;If it fails to connect, then opening connection allocation window, user is allowed to input.
S411, link information global buffer.
That is cache database link model.
S412, loading of databases table to interface.
It, In yet another embodiment, can be with customized table name, column name for embodiment shown in Fig. 2.User-defined data table Name, column name be " from template generation " in a function.It is the requirement in order to cooperate template to data source, to increase table Name, the customized name window of column name.After user selects table name, program is inquired its column list of file names by table name, and data are encapsulated In pairs as passing to customized name window.There is programmed logic automatically object rendering on interface in window, user is just at this time The customized table name in interface, column name can be passed through.Specifically, as shown in fig. 6, the method also includes following steps:
S501, according to customized table name, obtain database table.
Specifically, user selects a database table.
S502, column name is inquired by table name.
Program is inquired the column list of file names of this table by the table name of selection.
S503, the column name of the database table found is packaged into model object.
Column list of file names is packaged into FrameInfo model object.
S504, the transmitting model object to customized name window.
The model object is transmitted to customized name window.
S505, the model object is rendered on the customized name window.
The loading method of customized name window is rendered into model object on interface.
The modification of S506, reception to the column name.
User can modify table name, column name by interface.
Whether S507, confirmation modification, if it is, proceeding to S508;Otherwise, terminate process.
User confirms modification.If user closes window, terminate process.
S508, return mapping relationship object.
Return to modified FrameInfo model object.
S509, it is shown to template data list, saves modified model object.
" from template generation " essence be table inside data become code, and existing solution is only " from data Library generates " function, i.e., table structure is become code.
The realization principle of the application is that database table information (structure, data) is relied on to realize that code is automatic using template engine It generates.
The scheme of the application has the advantage that
1. realizing function using template, do not limited by the programming language for generating code, each language codes can be generated, is had There is good scalability, does not need modification program or extension element.
2. there are two types of the modes of generation: generating, from database from template generation, cover various actual conditions.
3. uniform data bank interface, compatible multitype database.
4. connecting using pouring-in window configuration data library, function can be achieved with using features tab on data model, It facilitates programmer and carries out coding extension.
5. providing edit model example and data source prompt information, reduce edit model difficulty.
6. providing drag operation enhances user experience.
7. providing memory function, avoid repeating configuration database connection, input basic information every time.
Described above is the code automatic generation methods of the application, and code generator is described below.
Fig. 7 is a kind of modular structure schematic diagram of code generator provided by the embodiments of the present application.The code is automatic The framework of generator 1000 is as shown in Figure 1.The code generator 1000 includes: that the first receiving unit 11, first obtains list Member 12, connection unit 13, second acquisition unit 14, third acquiring unit 15, the 4th acquiring unit 16, configuration unit 17 and generation Unit 18.Wherein:
First receiving unit 11, for receiving data selection instruction in library;
First acquisition unit 12, the connection for obtaining target database according to the selection instruction configure;
Connection unit 13 connects the target database for configuring according to the connection of the target database;
Second acquisition unit 14, for obtaining the information of the database table in the target database;
Third acquiring unit 15, for obtaining the template for generating code;
4th acquiring unit 16, for obtaining interface configurations;
Configuration unit 17, for according to the interface configurations, configuration interface;
Generation unit 18, for running template engine on the interface, according to the information of the database table and described Template generation code file.
In one implementation, the code generator further include: the second receiving unit, for receiving connection number According to the information in library;Fills unit, for the information to be filled into the data model of the database;Concatenation unit is used for Splice to obtain connection string using the information being filled into the data model;Test cell, for testing the database Connection;And first storage unit, the connection for storing the database configure.
In another implementation, first storage unit is used to the connection configuration of the database carrying out sequence Change;And the connection configuration of the database after the storage serializing, wherein the corresponding number of the type of a database It is configured according to the connection in library.
In another implementation, the code generator further include: third receiving unit, for receiving user Interface configurations, the interface configurations include following one or more information: type of database, whether automatic loading of databases Table, project name, tester;The interface configurations are serialized;And second storage unit, for storing the serializing Interface configurations afterwards.
In another implementation, the generation unit is for running template engine on the interface, using described Data source of the data information as the template in database table, utilizes the template generation code file.
In another implementation, the code generator further include: the 5th acquiring unit is made by oneself for basis The table name of justice obtains database table;Encapsulation unit, for the column name of the database table found to be packaged into model pair As;Rendering unit, for the model object to be rendered into customized name window;Unit is modified, for making by oneself described The modification to the column name is received on justice name window;And storage unit, for saving modified model object.
In another implementation, the generation unit is for running template engine on the interface, using described The data source of table name and column name as the module in database, utilizes the template generation code file.
According to a kind of code generator provided by the embodiments of the present application, can be matched according to the connection of the database of preservation It sets and interface configurations, information is obtained from database table, using template automatic code generating, using the template engine of open source, mould Plate grammer relatively easily learns, and is also easy to extend, and does not limit the programming language for generating code, does not limit technology.
Fig. 8 is a kind of hardware structural diagram of code generator provided by the embodiments of the present application.The code is automatic Generator 2000 may include: input unit 21, output device 22, memory 23 and processor 24.Memory 23 is for storing Computer program, computer program include program instruction, and processor 24 is used to execute the program instruction of the storage of memory 23.Its In, processor 24 is configured for caller instruction execution following steps:
Receive the selection instruction of database;
The connection configuration of target database is obtained according to the selection instruction;
It is configured according to the connection of the target database, connects the target database;
Obtain the information of the database table in the target database;
Obtain the template for generating code;
Obtain interface configurations;
According to the interface configurations, configuration interface;
Template engine is run on the interface, according to the information of the database table and template generation code text Part.
In one implementation, the processor 24 is also used to execute following steps: receiving the information of connection database; The information is filled into the data model of the database;Splice to obtain using the information being filled into the data model Connection string;Test the database connection;And the connection configuration of the storage database.
In another implementation, the processor 24 executes the step of the connection configuration of the storage database Suddenly, comprising: serialize the connection configuration of the database;And the company of the database after the storage serializing Connect configuration, wherein the connection configuration of the corresponding database of the type of a database.
In another implementation, the processor 24 is also used to execute following steps: the interface configurations of user are received, The interface configurations include following one or more information: type of database, whether automatic loading of databases table, project name, Tester;The interface configurations are serialized;And the interface configurations after the storage serializing.
In another implementation, the processor 24 execute it is described run template engine on the interface, according to The step of information of the database table and the template generation code file, comprising: template engine is run on the interface, Using the data information in the database table as the data source of the template, the template generation code file is utilized.
In another implementation, the processor 24 is also used to execute following steps: according to customized table name, obtaining Take database table;The column name of the database table found is packaged into model object;The model object is rendered into certainly On definition name window;The modification to the column name is received on the customized name window;And save modified mould Type object.
In another implementation, the processor 24 execute it is described run template engine on the interface, according to The step of information of the database table and the template generation code file, comprising: template engine is run on the interface, Using in the database table name and column name as the data source of the module, utilize the template generation code file.
It should be appreciated that in the embodiment of the present application, alleged processor 24 can be central processing unit (Central Processing Unit, CPU), which can also be other general processors, digital signal processor (Digital Signal Processor, DSP), specific integrated circuit (Application Specific Integrated Circuit, ASIC), ready-made programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic Device, discrete gate or transistor logic, discrete hardware components etc..General processor can be microprocessor or this at Reason device is also possible to any conventional processor etc..
Output device 22 is used for output data, and input unit 21 is used for input data.
The memory 23 may include read-only memory and random access memory, and provide instruction sum number to processor 24 According to.The a part of of memory 23 can also include nonvolatile RAM.It is set for example, memory 23 can also store The information of standby type.
In the specific implementation, processor 24, output device 22 described in the embodiment of the present application and input unit 21 can be held A kind of embodiment for code automatic generation method that row the embodiment of the present application Fig. 2~Fig. 6 is provided, details are not described herein.
According to a kind of code generator provided by the embodiments of the present application, can be matched according to the connection of the database of preservation It sets and interface configurations, information is obtained from database table, using template automatic code generating, using the template engine of open source, mould Plate grammer relatively easily learns, and is also easy to extend, and does not limit the programming language for generating code, does not limit technology.
It is apparent to those skilled in the art that for convenience and simplicity of description, the system of foregoing description, The specific work process of code generator and unit, can refer to corresponding processes in the foregoing method embodiment, herein not It repeats again.
In several embodiments provided herein, it should be understood that disclosed system, code generator and Method may be implemented in other ways.For example, the division of the unit, only a kind of logical function partition is practical to realize When there may be another division manner, for example, multiple units or components can be combined or can be integrated into another system, or Some features can be ignored or not executed.Shown or discussed mutual coupling or direct-coupling or communication connection Can be through some interfaces, the indirect coupling or communication connection of code generator or unit, can be electrical property, it is mechanical or Other forms.
Unit may or may not be physically separated as illustrated by the separation member, shown as a unit Component may or may not be physical unit, it can and it is in one place, or may be distributed over multiple networks On unit.It can some or all of the units may be selected to achieve the purpose of the solution of this embodiment according to the actual needs.
In the above-described embodiments, can come wholly or partly by software, hardware, firmware or any combination thereof real It is existing.When implemented in software, it can entirely or partly realize in the form of a computer program product.The computer program produces Product include one or more computer instructions.It is all or part of when loading and execute on computers the computer program instructions Ground generates the process or function according to the embodiment of the present application.The computer can be general purpose computer, special purpose computer, computer Network or other programmable code automatic generators.The computer instruction may be stored in a computer readable storage medium, Or it is transmitted by the computer readable storage medium.The computer instruction can be from web-site, computer, a clothes Be engaged in device or data center by it is wired (such as coaxial cable, optical fiber, Digital Subscriber Line (digital subscriber line, DSL)) or wireless (such as infrared, wireless, microwave etc.) mode is to another web-site, computer, server or data center It is transmitted.The computer readable storage medium can be any usable medium or include one that computer can access Or the data storage devices such as integrated server, data center of multiple usable mediums.The usable medium can be read-only memory (read-only memory, ROM) or random access memory (random access memory, RAM) or magnetic medium, For example, floppy disk, hard disk, tape, magnetic disk or optical medium, for example, digital versatile disc (digital versatile disc, DVD) or semiconductor medium, for example, solid state hard disk (solid state disk, SSD) etc..

Claims (10)

1. a kind of code automatic generation method, which is characterized in that the described method includes:
Receive the selection instruction of database;
The connection configuration of target database is obtained according to the selection instruction;
It is configured according to the connection of the target database, connects the target database;
Obtain the information of the database table in the target database;
Obtain the template for generating code;
Obtain interface configurations;
According to the interface configurations, configuration interface;
Template engine is run on the interface, according to the information of the database table and the template generation code file.
2. the method according to claim 1, wherein the method also includes:
Receive the information of connection database;
The information is filled into the data model of the database;
Splice to obtain connection string using the information being filled into the data model;
Test the database connection;
Store the connection configuration of the database.
3. according to the method described in claim 2, it is characterized in that, the connection configuration of the storage database, comprising:
The connection configuration of the database is serialized;
The connection of the database after storing the serializing configures, wherein the corresponding data of the type of a database The connection in library configures.
4. the method as described in claim 1, which is characterized in that the method also includes:
The interface configurations of user are received, the interface configurations include following one or more information: type of database, whether automatic Loading of databases table, project name, tester;
The interface configurations are serialized;
Interface configurations after storing the serializing.
5. the method according to claim 1, wherein the method also includes:
According to customized table name, database table is obtained;
The column name of the database table found is packaged into model object;
The model object is rendered on customized name window;
The modification to the column name is received on the customized name window;
Save modified model object.
6. according to the method described in claim 5, it is characterized in that, described run template engine on the interface, according to institute State the information and the template generation code file of database table, comprising:
Run template engine on the interface, using in the database table name and column name as the data of the module Source utilizes the template generation code file.
7. according to the described in any item methods of claim 2~4, which is characterized in that the template that runs on the interface is drawn It holds up, according to the information of the database table and the template generation code file, comprising:
Template engine is run on the interface, using the data information in the database table as the data of the template Source utilizes the template generation code file.
8. a kind of code generator, which is characterized in that the code generator includes:
First receiving unit, for receiving data selection instruction in library;
First acquisition unit, the connection for obtaining target database according to the selection instruction configure;
Connection unit connects the target database for configuring according to the connection of the target database;
Second acquisition unit, for obtaining the information of the database table in the target database;
Third acquiring unit, for obtaining the template for generating code;
4th acquiring unit, for obtaining interface configurations;
Configuration unit, for according to the interface configurations, configuration interface;
Generation unit, it is raw according to the information of the database table and the template for running template engine on the interface At code file.
9. a kind of code generator, which is characterized in that including processor, input equipment, output equipment and memory, In, the memory is for storing computer program, and the computer program includes program instruction, and the processor is configured to use In calling described program instruction, such as method of any of claims 1-7 is executed.
10. a kind of computer storage medium, which is characterized in that the computer storage medium is stored with computer program, described Computer program includes program instruction, and described program is instructed when being executed by a processor, executed such as any one of claim 1-7 The method.
CN201910075242.XA 2019-01-25 2019-01-25 A kind of code automatic generation method and code generator Pending CN109885291A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910075242.XA CN109885291A (en) 2019-01-25 2019-01-25 A kind of code automatic generation method and code generator

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910075242.XA CN109885291A (en) 2019-01-25 2019-01-25 A kind of code automatic generation method and code generator

Publications (1)

Publication Number Publication Date
CN109885291A true CN109885291A (en) 2019-06-14

Family

ID=66926946

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910075242.XA Pending CN109885291A (en) 2019-01-25 2019-01-25 A kind of code automatic generation method and code generator

Country Status (1)

Country Link
CN (1) CN109885291A (en)

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110580159A (en) * 2019-09-16 2019-12-17 上海巨灵信息技术股份有限公司 automatic software code generation method and system
CN110837363A (en) * 2019-11-05 2020-02-25 北京锐安科技有限公司 Code file generation method, device, equipment and medium
CN111061475A (en) * 2019-12-13 2020-04-24 中国南方电网有限责任公司 Software code generation method and device, computer equipment and storage medium
CN111198680A (en) * 2019-12-20 2020-05-26 江苏原力动画制作股份有限公司 File generation system and method based on Arnold renderer
CN111427567A (en) * 2020-03-20 2020-07-17 杭州涂鸦信息技术有限公司 Intelligent product rapid generation method, system and equipment thereof
CN111562908A (en) * 2020-04-15 2020-08-21 北京明略软件系统有限公司 Code generation method and device
CN111580794A (en) * 2020-05-06 2020-08-25 山东浪潮通软信息科技有限公司 Method and device for creating business document in business management system
CN111796810A (en) * 2020-07-03 2020-10-20 福建天晴在线互动科技有限公司 Method and system for configurable rapid generation of Mysql database codes
CN113296760A (en) * 2021-05-25 2021-08-24 深信服科技股份有限公司 Method for generating model code, computer device and readable storage medium
CN113535141A (en) * 2020-04-16 2021-10-22 浙江大搜车软件技术有限公司 Database operation code generation method and device
TWI757743B (en) * 2019-09-17 2022-03-11 開曼群島商創新先進技術有限公司 Mini program generation method and device
CN114741070A (en) * 2022-04-12 2022-07-12 中国联合网络通信集团有限公司 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
CN103412749A (en) * 2013-07-29 2013-11-27 福建联迪商用设备有限公司 Relational database based code generation method and code generator
CN104317576A (en) * 2014-07-04 2015-01-28 北京思特奇信息技术股份有限公司 Code automatic generation method and system based on eclipse
CN106873974A (en) * 2016-12-30 2017-06-20 武汉默联股份有限公司 Smart code generates automotive engine system and method
CN107357588A (en) * 2017-07-19 2017-11-17 万帮充电设备有限公司 Object Code Generator method and device
CN107729003A (en) * 2017-11-20 2018-02-23 江苏神州信源系统工程有限公司 Automatic generation method, device and the electronic equipment of code

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103412749A (en) * 2013-07-29 2013-11-27 福建联迪商用设备有限公司 Relational database based code generation method and code generator
CN104317576A (en) * 2014-07-04 2015-01-28 北京思特奇信息技术股份有限公司 Code automatic generation method and system based on eclipse
CN106873974A (en) * 2016-12-30 2017-06-20 武汉默联股份有限公司 Smart code generates automotive engine system and method
CN107357588A (en) * 2017-07-19 2017-11-17 万帮充电设备有限公司 Object Code Generator method and device
CN107729003A (en) * 2017-11-20 2018-02-23 江苏神州信源系统工程有限公司 Automatic generation method, device and the electronic equipment of code

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
张季谦等: "《网页设计与制作》", 31 January 2017, 中国科学技术大学出版社 *

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110580159A (en) * 2019-09-16 2019-12-17 上海巨灵信息技术股份有限公司 automatic software code generation method and system
TWI757743B (en) * 2019-09-17 2022-03-11 開曼群島商創新先進技術有限公司 Mini program generation method and device
CN110837363A (en) * 2019-11-05 2020-02-25 北京锐安科技有限公司 Code file generation method, device, equipment and medium
CN111061475A (en) * 2019-12-13 2020-04-24 中国南方电网有限责任公司 Software code generation method and device, computer equipment and storage medium
CN111061475B (en) * 2019-12-13 2023-12-12 中国南方电网有限责任公司 Software code generating method, device, computer equipment and storage medium
CN111198680A (en) * 2019-12-20 2020-05-26 江苏原力动画制作股份有限公司 File generation system and method based on Arnold renderer
CN111198680B (en) * 2019-12-20 2020-12-11 江苏原力数字科技股份有限公司 File generation system and method based on Arnold renderer
CN111427567A (en) * 2020-03-20 2020-07-17 杭州涂鸦信息技术有限公司 Intelligent product rapid generation method, system and equipment thereof
CN111427567B (en) * 2020-03-20 2023-08-18 杭州涂鸦信息技术有限公司 Intelligent product rapid generation method, system and equipment thereof
CN111562908A (en) * 2020-04-15 2020-08-21 北京明略软件系统有限公司 Code generation method and device
CN113535141A (en) * 2020-04-16 2021-10-22 浙江大搜车软件技术有限公司 Database operation code generation method and device
CN111580794A (en) * 2020-05-06 2020-08-25 山东浪潮通软信息科技有限公司 Method and device for creating business document in business management system
CN111796810A (en) * 2020-07-03 2020-10-20 福建天晴在线互动科技有限公司 Method and system for configurable rapid generation of Mysql database codes
CN113296760A (en) * 2021-05-25 2021-08-24 深信服科技股份有限公司 Method for generating model code, computer device and readable storage medium
CN114741070A (en) * 2022-04-12 2022-07-12 中国联合网络通信集团有限公司 Code generation method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN109885291A (en) A kind of code automatic generation method and code generator
CN107451663B (en) Algorithm componentization, modeling method and device based on algorithm components and electronic equipment
CN109358936A (en) Information processing method, device, storage medium, electronic equipment and system
CN109213962A (en) Arithmetic accelerator
CN112256321A (en) Static library packaging method and device, computer equipment and storage medium
CN107015804A (en) A kind of method and system by the quick exploration project of provisioning API
US20150089469A1 (en) Computer-aided development of native mobile application code
CN109491708A (en) Document structure tree method, system, equipment and medium
CN110032368B (en) Information configuration method and device
CN111353235A (en) Component port modeling method based on model drive and terminal
CN104063231B (en) Test resource rapid access method based on HIT-TENA
CN104471530B (en) Executable software code generation
CN109542563A (en) One kind integrating multi-mode Android page management method, apparatus and system
CN108595331A (en) Test method, medium, device and the computing device of asynchronous interface
Steiner A standalone wire database for routing and tracing in Xilinx Virtex, Virtex-E, and Virtex-II FPGAs
CN109388406A (en) Convert method and device, the storage medium, electronic device of java code
CN116956787A (en) Method and device for converting XMR signal transmission mode
WO2018058612A1 (en) Configuration method and system
CN116738954A (en) Report export method, report template configuration device and computer equipment
CN112181418B (en) Rapid construction method and system for nuclear reactor computing software graphical interface
CN109960503A (en) Component development method and device based on Django framework
CN115129392A (en) Chip configuration method and device, computer equipment and storage medium
CN113342399A (en) Application structure configuration method and device and readable storage medium
CN104272294B (en) Generate the method and system of particular system framework
CN102081517A (en) User interface display method and apparatus

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20190614