CN113760352A - Code file generation method, electronic device, storage medium, and program product - Google Patents

Code file generation method, electronic device, storage medium, and program product Download PDF

Info

Publication number
CN113760352A
CN113760352A CN202110746081.XA CN202110746081A CN113760352A CN 113760352 A CN113760352 A CN 113760352A CN 202110746081 A CN202110746081 A CN 202110746081A CN 113760352 A CN113760352 A CN 113760352A
Authority
CN
China
Prior art keywords
configuration
code
file
information
data table
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
CN202110746081.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.)
Beijing Fangjianghu Technology Co Ltd
Original Assignee
Beijing Fangjianghu 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 Beijing Fangjianghu Technology Co Ltd filed Critical Beijing Fangjianghu Technology Co Ltd
Priority to CN202110746081.XA priority Critical patent/CN113760352A/en
Publication of CN113760352A publication Critical patent/CN113760352A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • G06F16/164File meta data generation

Abstract

The invention provides a code file generation method, electronic equipment, a storage medium and a program product, wherein the method comprises the following steps: acquiring corresponding configuration information comprising package path configuration and file naming configuration of at least one code file according to the configuration group information; obtaining a package path and a file name according to the package path configuration, the file name configuration and the description information of the data table; generating an instantiation object corresponding to the configuration information based on the package path, the file name, the description information of the data table and the information of the data field; and combining the instantiation object with the code template corresponding to the code file to generate a corresponding code file. According to the code file generation method, the electronic device, the storage medium and the program product, the common operation is configured and managed, so that the subsequent selection and maintenance cost is reduced, the effective management of configuration information is realized, the expansibility, the flexibility, the usability and the universality of code generation are enhanced, and the code generation efficiency is improved.

Description

Code file generation method, electronic device, storage medium, and program product
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a code file generation method, an electronic device, a storage medium, and a program product.
Background
In project development, new business fields or application scenes are frequently added, operations such as adding, deleting, modifying, checking and the like are indispensable to be performed on the basis of codes of the new business fields or application scenes, and codes of the corresponding business fields or application scenes can be generated by adopting a code generation method. Related code files can be quickly generated through a code generation technical means, the generated codes are similar in style and simple in logic, the workload of technicians is greatly reduced, and meanwhile, the research and development efficiency is improved. In the field of project development, particularly in the field of service-side project development, the code generation technology has high practical value.
The existing code file generation methods can be roughly divided into two types: IDE (Integrated Development Environment) plug-in based code generation and Web site based code generation. Most of them rely on built-in code template and data table related information to generate fixed style codes. In the existing code file generation method, each information for generating the code file needs to be input every time the code is generated, such as inputting a package path and file naming of each code file, which brings great inconvenience and low code generation efficiency.
Disclosure of Invention
In order to solve the problems in the prior art, the invention provides a code file generation method, electronic equipment, a storage medium and a program product.
The invention provides a code file generation method, which comprises the following steps: acquiring configuration group information, and acquiring corresponding configuration information according to the configuration group information; wherein the configuration information comprises a package path configuration and a file naming configuration of at least one code file; acquiring description information of a data table and information of data fields in the data table; obtaining a package path and a file name according to the package path configuration, the file name configuration and the description information of the data table; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; and combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file.
According to the code file generation method provided by the invention, the configuration information further comprises type mapping configuration; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table, and the information of the data field, specifically including: performing data type conversion on the data field according to the type mapping configuration; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; and the information of the data field comprises the name of the data field and the converted data type.
According to the code file generation method provided by the present invention, the combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file specifically includes: obtaining a method screening result of the code template of the corresponding level of the code file; wherein the screening result of the method comprises a selected method and an unselected method; and combining the instantiation object with the code template corresponding to the code file, and generating the corresponding code file aiming at the selected method.
According to a code file generation method provided by the present invention, before the instantiation object is combined with a code template corresponding to the code file to generate the corresponding code file, the method further includes: and acquiring a code template selection result, and acquiring the code template according to the code template selection result.
According to a code file generation method provided by the present invention, before the obtaining of the configuration group information, the method further includes: displaying a code generation configuration interface, wherein the code generation configuration interface comprises at least one of a data definition language information input sub-interface, a configuration group selection sub-interface, a template selection sub-interface and a method selection sub-interface; the data definition language information input sub-interface is used for receiving input data definition language information, and the data definition language information is used for analyzing and obtaining description information of the data table and information of the data fields in the data table; the configuration group selection sub-interface is used for acquiring the configuration group information; the template selection sub-interface is used for acquiring the code template selection result; the method selection sub-interface is used for obtaining the method screening results of the code templates of different levels.
According to the code file generation method provided by the invention, the description information of the data table comprises the name of the data table; the method further comprises the following steps: in the package path configuration and/or the file naming configuration, representing the data table name by using a preset variable; the obtaining of the package path and the file name according to the package path configuration, the file name configuration and the description information of the data table specifically includes: judging whether the packet path configuration contains the preset variable or not, if so, replacing the preset variable in the packet path configuration with the data table name or with a character obtained by converting the data table name through a preset first format, and obtaining the packet path; if not, directly configuring the packet path as the packet path; judging whether the file naming configuration contains the preset variable or not, if so, replacing the preset variable in the file naming configuration with the data table name or replacing the preset variable with a character obtained after the data table name is subjected to preset second format conversion, and obtaining the file naming; if not, the file naming configuration is directly used as the file naming.
According to a code file generation method provided by the present invention, after the corresponding code file is generated, the method further includes: and respectively generating corresponding folders for the at least one code file according to the corresponding package paths, compressing and packaging the code files, and storing the compressed packages under a preset path.
The present invention also provides a code file generating apparatus, including: a configuration information acquisition module for: acquiring configuration group information, and acquiring corresponding configuration information according to the configuration group information; wherein the configuration information comprises a package path configuration and a file naming configuration of at least one code file; a table information acquisition module to: acquiring description information of a data table and information of data fields in the data table; an instantiated object acquisition module to: obtaining a package path and a file name according to the package path configuration, the file name configuration and the description information of the data table; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; a code file generation module to: and combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file.
The invention also provides an electronic device, which comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the processor executes the program to realize the steps of the code file generation method.
The present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the code file generation method as described in any of the above.
The present invention also provides a computer program product comprising computer programs/instructions, characterized in that said computer programs/instructions, when executed by a processor, implement the steps of the code file generation method as described in any of the above.
According to the code file generation method, the electronic equipment, the storage medium and the program product, configuration group information is obtained, corresponding configuration information comprising package path configuration and file naming configuration of at least one code file is obtained according to the configuration group information, description information of a data table and information of data fields in the data table are obtained, and package paths and file names are obtained according to the package path configuration, the file naming configuration and the description information of the data table; the method comprises the steps of generating an instantiation object corresponding to configuration information based on package paths, file naming, description information of a data table and information of data fields, combining the instantiation object with a code template corresponding to a code file to generate a corresponding code file, and performing configuration management on common operations, so that the subsequent selection and maintenance cost is reduced, the effective management of the configuration information is realized, the expansibility, the flexibility, the usability and the universality of code generation are enhanced, and the code generation efficiency is improved.
Drawings
In order to more clearly illustrate the technical solutions of the present invention or the prior art, the drawings needed for the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
FIG. 1 is a flow chart of a code file generation method provided by the present invention;
FIG. 2 is a schematic diagram of configuration information in the code file generation method provided by the present invention;
FIG. 3 is an example of DDL of a data table in the code file generation method provided by the present invention;
FIG. 4 is an example of table information obtained by DDL parsing in the code file generation method provided by the present invention;
FIG. 5 is a schematic diagram of a code template in the code file generation method provided by the present invention;
FIG. 6 is a diagram illustrating the selection of a corresponding code template method in the code file generation method provided by the present invention;
FIG. 7 is a second flowchart illustrating a code file generation method according to the present invention;
FIG. 8 is a schematic diagram of a code generation configuration interface in the code file generation method provided in the present invention;
FIG. 9 is a schematic structural diagram of a code file generation apparatus provided in the present invention;
fig. 10 is a schematic structural diagram of an electronic device provided by the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is obvious that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The code file generating method, the electronic device, the storage medium, and the program product provided by the present invention are described below with reference to fig. 1 to 10. In the description of the specific embodiment, the generation of java code file is taken as an example for description, and is not intended to limit the protection scope of the code file generation method provided by the present invention.
Fig. 1 is a schematic flow chart of a code file generation method provided by the present invention. As shown in fig. 1, the method includes:
step 101, acquiring configuration group information, and acquiring corresponding configuration information according to the configuration group information; wherein the configuration information includes a package path configuration and a file naming configuration of at least one code file.
Each user can create a plurality of configuration groups, and each configuration group is named uniquely for the convenience of subsequent management and use. Each configuration group corresponds to corresponding configuration information.
Fig. 2 is a schematic diagram of configuration information in the code file generation method provided by the present invention. As shown in fig. 2, the configuration information includes a configuration group name and a package path configuration and a file name configuration of at least one code file. In a development project, the code files are divided into different hierarchies, and the code files of each hierarchy correspond to package paths and file names. In the configuration information of each configuration group, package path configuration and file naming configuration are performed for code files of each hierarchy. The pack path is for identifying the position of the code file with respect to the [ code engineering root directory ]. When the code file is used, folders are created step by step relative to the code engineering root directory, and then the corresponding code file is stored under the folders.
102, obtaining description information of a data table and information of data fields in the data table.
The table information may be obtained by Data Definition Language (DDL) information analysis of the Data table. The table information can be obtained specifically according to the DDL grammar keywords and the regular expression. The table information includes description information of the data table and information of data fields in the data table. The description information of the data table may include a name and a description of the data table. The information of the data fields may include the name, type, and description of all the fields of the data table.
FIG. 3 is an example of DDL of a data table in the code file generation method provided by the present invention.
Fig. 4 is an example of table information obtained by DDL parsing in the code file generation method provided by the present invention.
103, obtaining a package path and a file name according to the package path configuration, the file name configuration and the description information of the data table; and generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field.
The file name is associated with the data table name, and the package path may also be associated with the data table name. Therefore, the package path and the file name can be obtained according to the package path configuration, the file name configuration and the description information of the data table. And generating an instantiation object corresponding to the configuration information based on the package path, the file name, the description information of the data table and the information of the data field. The instantiation object comprises package path, file name, description information of a data table and information of a data field.
And 104, combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file.
Fig. 5 is a schematic diagram of a code template in the code file generation method provided by the present invention. As shown in fig. 5, a template file corresponding to the Service file is shown. Velocity is a Java-based template engine. It allows simple use of the template language to reference objects defined by java code. The method provides a Context container, objects can be stored in the container in Java codes, and then specific grammar is used for obtaining in a Velocity template file, so that functions of condition judgment, variable replacement and the like are achieved. And defining a Velocity template to provide a master plate for subsequent code generation. Based on the capability of the Velocity, converting the rules defined by the user into Java objects, putting the Java objects into a Context container, and creating a tool for producing source codes by configuring a universal Velocity template file. Aiming at each Java code file to be generated, a system template corresponding to the Java code file is provided, and rich methods are provided for realizing: adding, deleting, changing, main key checking, condition updating, paging condition checking and the like. There is fine control for each implementation of each level.
The existing capabilities of the template engine can be utilized to generate the code file, and the template engine needs two types of information, one is the template file and the other is the container. The template file is used for defining the format of the generated file, and the container is used for accommodating data variables required to be used in the code template. And after the instantiation object is obtained, putting the instantiation object into a container in a template engine, and combining the instantiation object and the code template corresponding to the code file to generate a corresponding code file. Thus, code files for different levels of the project may be separately available. Of course, some code files may be at the same level. If the Java object corresponding to the configuration information is generated according to the configuration group information Configgroup selected by the user and by combining the table information TableInfo analyzed by the data analysis module, the Java object is put into a Context container of Velocity, and the Java object of the configuration information mainly comprises three types of information: package path, file name, data field information. The object is put into a Context container of Velocity, and the corresponding data variable, such as $ { table. servicename }, can be used in the template to obtain the corresponding variable value IBusinsecessAccountservice. And then combining the java objects of the configuration information with each vector template to generate corresponding code files.
The code file generation method provided by the invention comprises the steps of acquiring configuration group information, acquiring corresponding configuration information comprising package path configuration and file naming configuration of at least one code file according to the configuration group information, acquiring description information of a data table and information of data fields in the data table, and acquiring package paths and file names according to the package path configuration, the file naming configuration and the description information of the data table; the method comprises the steps of generating an instantiation object corresponding to configuration information based on package paths, file naming, description information of a data table and information of data fields, combining the instantiation object with a code template corresponding to a code file to generate a corresponding code file, and performing configuration management on common operations, so that the subsequent selection and maintenance cost is reduced, the effective management of the configuration information is realized, the expansibility, the flexibility, the usability and the universality of code generation are enhanced, and the code generation efficiency is improved.
According to the code file generation method provided by the invention, the configuration information further comprises type mapping configuration; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table, and the information of the data field, specifically including: performing data type conversion on the data field according to the type mapping configuration; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; and the information of the data field comprises the name of the data field and the converted data type.
As shown in fig. 2, the configuration information also includes a type mapping configuration. The mapping of data types is to satisfy different appeal of different users to type mapping. Such as: for JDBC data type tinyint (1), it can be mapped to a plurality of different data types Boolean, Byte, Short or Integer of Java. The extended design of the type mapping is carried out, and different requirements of users for the type mapping are met.
When an instantiation object corresponding to configuration information is generated based on package paths, file names, description information of a data table and information of data fields, firstly, data types of the data fields are converted according to type mapping configuration, and then the instantiation object corresponding to the configuration information is generated based on the package paths, the file names, the description information of the data table and the information of the data fields; the information of the data field comprises the name of the data field and the converted data type.
As shown in the following example, according to the type mapping in the configuration group information ConfigGroup, the mapping from the field type in the table information to the Java data type is completed:
before mapping:
Figure BDA0003144432690000091
Figure BDA0003144432690000101
after mapping:
Figure BDA0003144432690000102
the instantiation objects generated are as follows:
Figure BDA0003144432690000103
Figure BDA0003144432690000111
according to the code file generation method provided by the invention, the data type of the data field in the data table is converted according to the type mapping configuration to generate the instantiation object, so that the flexible configuration of the data type mapping is improved, and the expansibility is improved.
According to the code file generation method provided by the present invention, the combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file specifically includes: obtaining a method screening result of the code template of the corresponding level of the code file; wherein the screening result of the method comprises a selected method and an unselected method; and combining the instantiation object with the code template corresponding to the code file, and generating the corresponding code file aiming at the selected method.
Different from the method library in the code template in the prior art, which can not be selected according to needs and can only be generated in full quantity, the code file generation method provided by the invention provides a method selection function of the code template, thereby providing finer granularity control for the generated code. Since the methods of the code files at the same level are the same, the methods of the code files at different levels may be different. Thus, the selection of the method may be configured hierarchically. After the code templates corresponding to the code files of the same level are configured by the method once, the code files of the same level can be generated by using the corresponding method configuration results.
Since the code files differentiate the hierarchy, the templates to which the code files correspond also differentiate the hierarchy accordingly. When the instantiation object is combined with the code template corresponding to the code file to generate a corresponding code file, obtaining a method screening result of the code template of the corresponding hierarchy of the code file; wherein, the method screening result comprises a selected method and an unselected method; and combining the instantiation object with the code template corresponding to the code file, and generating a corresponding code file aiming at the selected method.
Fig. 6 is a schematic diagram of a method selection corresponding to a code template in the code file generation method provided by the present invention. As shown in fig. 6, the most classic three layers of Java Web project are Controller, Service, and Dao, and the code template provides a rich implementation interface (method) for the user to select. However, when part of the interfaces are not suitable for exposure or are not needed by the user, the user can not select the corresponding method of the corresponding hierarchy, and more accurate granularity control and better flexibility are embodied.
The hierarchical division of the code file is a specification agreed in project development, such as that Service and Servicelmpl belong to the same hierarchy. In the hierarchical configuration method, the method configuration may be performed for one of the code templates in the same hierarchy. If the user selects (e.g., checks in the interactive interface) the corresponding method, the variable corresponding to the method is true, and if the method is not checked, the variable is false. The method selection information also needs to be put into a container of the code engine, such as a Context container of Velocity, and after the method selection, the code template already contains the judgment of the corresponding variable, such as: if the service, methodadd variable is true, then the corresponding add method will be generated in the code file, and if the service, methoddel variable is false, then the corresponding delete method will not be generated in the code file.
The data format of the method selection information is as follows:
Figure BDA0003144432690000131
according to the code file generation method provided by the invention, the corresponding code file is generated by aiming at the selected method through the method screening result of the corresponding level code template, so that the flexibility of code file generation is further improved.
According to a code file generation method provided by the present invention, before the instantiation object is combined with a code template corresponding to the code file to generate the corresponding code file, the method further includes: and acquiring a code template selection result, and acquiring the code template according to the code template selection result.
For each code file, a different code template may be configured. Before combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file, firstly, obtaining a code template selection result, obtaining the code template according to the code template selection result, and then, combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file.
According to the code file generation method provided by the invention, the code template is obtained according to the code template selection result, and the instantiation object and the code template corresponding to the code file are combined to generate the corresponding code file, so that the flexibility of code file generation is further improved.
According to a code file generation method provided by the present invention, before the obtaining of the configuration group information, the method further includes: displaying a code generation configuration interface, wherein the code generation configuration interface comprises at least one of a data definition language information input sub-interface, a configuration group selection sub-interface, a template selection sub-interface and a method selection sub-interface; the data definition language information input sub-interface is used for receiving input data definition language information, and the data definition language information is used for analyzing and obtaining description information of the data table and information of the data fields in the data table; the configuration group selection sub-interface is used for acquiring the configuration group information; the template selection sub-interface is used for acquiring the code template selection result; the method selection sub-interface is used for obtaining the method screening results of the code templates of different levels.
A code generation configuration interface may be provided, and before generating the code file, the code generation configuration interface is presented to receive the corresponding configuration result. The code generation configuration interface may include at least one of a data definition language information input sub-interface, a configuration group selection sub-interface, a template selection sub-interface, and a method selection sub-interface. The Data Definition Language (DDL) information input sub-interface is used for receiving input data definition language information, and the description information of a data table and the information of data fields in the data table can be obtained by analyzing the input data definition language information; the configuration group selection sub-interface is used for selecting a configuration group and obtaining configuration group information according to a selection result; the template selection sub-interface is used for selecting a code template and obtaining a code template selection result according to the selection result; and the method selection sub-interface is used for selecting the methods to be generated in the code templates of different levels and acquiring the method screening results according to the selection results.
According to the code file generation method provided by the invention, the code generation configuration interface comprising at least one of the data definition language information input sub-interface, the configuration group selection sub-interface, the template selection sub-interface and the method selection sub-interface is set, so that the operation is simpler, more convenient and more intuitive, and the usability is improved.
According to the code file generation method provided by the invention, the description information of the data table comprises the name of the data table; the method further comprises the following steps: in the package path configuration and/or the file naming configuration, representing the data table name by using a preset variable; the obtaining of the package path and the file name according to the package path configuration, the file name configuration and the description information of the data table specifically includes: judging whether the packet path configuration contains the preset variable or not, if so, replacing the preset variable in the packet path configuration with the data table name or with a character obtained by converting the data table name through a preset first format, and obtaining the packet path; if not, directly configuring the packet path as the packet path; judging whether the file naming configuration contains the preset variable or not, if so, replacing the preset variable in the file naming configuration with the data table name or replacing the preset variable with a character obtained after the data table name is subjected to preset second format conversion, and obtaining the file naming; if not, the file naming configuration is directly used as the file naming.
In the packet path configuration and/or the file naming configuration, a preset variable is used for replacing a data table name; the preset variable may be expressed in% s, for example. Besides the preset variables, the package path configuration and the file naming configuration can also include other information, for example, in the file naming configuration, any prefix and suffix can be added to the preset variables, so that the extremely high flexibility is realized, and different naming styles and specifications of users can be met.
When a package path and a file name are obtained according to package path configuration, file name configuration and description information of a data table, judging whether the package path configuration contains a preset variable or not, if so, replacing the preset variable in the package path configuration with the name of the data table or replacing the preset variable with a character obtained by converting the name of the data table through a preset first format, and obtaining the package path; if not, directly configuring the packet path as the packet path. The preset first format conversion may be set according to a naming rule of the packet path, such as converting a data table name into a character string including only lower case letters. For example, if the data table name is businessjaccount, the data table name is businessaccount after the first format conversion.
Judging whether the file naming configuration contains a preset variable or not, if so, replacing the preset variable in the file naming configuration with a data table name or replacing the preset variable with a character obtained by converting the data table name through a preset second format to obtain a file name; if not, the file naming configuration is directly used as the file naming. The preset second format conversion may be set according to a file naming rule, such as converting a data table name according to a hump naming rule. For example, if the data table name is business _ account, the data table name is converted into BusinessAccount after the second format conversion.
If the packet path configuration includes the preset variable% s, the preset variable% s may be replaced with a character string businessaccount obtained by performing first format conversion on the data table name, so as to obtain the packet path. If the packet path configuration does not include the predetermined variable% s, as shown in fig. 2, the packet path configuration in fig. 2 may be directly used as the packet path. If the file name includes the preset variable% s, as shown in fig. 2, the preset variable% s may be replaced with a character string BusinessAccount obtained by performing second format conversion on the data table name, so as to obtain the file name. If the preset variable% s is not included in the file name, the file name configuration is directly used as the file name.
The file name acquisition process is as follows:
extracting table _ name in table information tablelnfo: business _ account, and converted to hump naming format: BusinessAccount, replaces this information with the% s character in the configuration information.
Format before replacement:
Figure BDA0003144432690000161
Figure BDA0003144432690000171
format after replacement:
Figure BDA0003144432690000172
according to the code file generation method provided by the invention, the preset variable is used for representing the name of the data table in the package path configuration and/or the file naming configuration, and the preset variable is replaced by the name of the data table or the character string obtained after the format conversion is carried out on the name of the data table, so that the package path and the file naming are obtained, and the flexibility of the package path and the file naming setting is improved.
According to a code file generation method provided by the present invention, after the corresponding code file is generated, the method further includes: and respectively generating corresponding folders for the at least one code file according to the corresponding package paths, compressing and packaging the code files, and storing the compressed packages under a preset path.
After the code files contained in the research and development project are generated, the code files contained in the research and development project are compressed and packaged and stored in a preset path for downloading. For example, by using the tool class under java.util.zip, all the generated code files are uniformly compressed and packed into zip files, and then the zip files are downloaded to the local path designated by the user for project development and use.
When the method is used, the compressed package is downloaded for decompression, and the code files are stored according to the package path (the corresponding file folder is created according to the configured package path during compression), so that the corresponding code files and file folders can be directly copied into a developed code project and then operated.
According to the code file generation method provided by the invention, at least one code file is compressed and packaged after corresponding folders are respectively generated according to the corresponding package path, and the compressed package is stored under the preset path, so that the practicability is improved.
FIG. 7 is a second flowchart illustrating a code file generation method according to the present invention. As shown in fig. 7, the method includes:
and analyzing the DDL of the data table to obtain the description information and the data field information of the data table. The method comprises the steps of managing type mapping, package paths and file names to realize configuration management, managing a system template to realize template management, carrying out data type conversion on data fields according to the type mapping configuration, obtaining package paths and file names according to package path configuration, file name configuration and data table names, selecting and obtaining method variables needing to be generated according to methods in the template, generating instantiation objects corresponding to configuration information based on package paths, file names, description information of data tables and information of data fields, putting the instantiation objects into a container in a template engine, and combining the instantiation objects with code templates corresponding to code files to generate code files of selected methods. And compressing and packaging the code files, storing the compressed and packaged code files into a specified path, and downloading the compressed and packaged code files when in use, so that the corresponding code files can be used.
The code generation method provided by the invention starts from an actual application scene, improves the usability of the system by adding type mapping extension points and a centralized configuration information management function, and further improves the working efficiency of technical personnel; and the expansibility, flexibility, usability and universality of code generation are improved. The problems that data type mapping and solidification cannot be flexibly configured and have poor expansibility, packet paths and naming styles for generating various Java classes in a project are too solidified and have poor universality, a method library in a code template cannot be selected as required and can only be generated in full, the flexibility is poor, configuration information is not effectively managed, repeated entry is needed for secondary use, the efficiency is very low, the usability is poor and the like in the conventional code generation method are solved.
FIG. 8 is a schematic diagram of a code generation configuration interface in the code file generation method provided by the present invention. As shown in fig. 8, the flow of the code generation method provided by the present invention is as follows:
1. completing configuration of a configuration group (only needed for the first use), mainly comprising mapping rules of data types, specification of package paths and naming rule definition of a generated code file, and referring to fig. 2;
2. filling in DDL information;
3. selecting a configuration group;
4. selecting a method to be generated;
5. the generation and downloading is performed.
In conclusion, the invention has the following advantages:
1. the operation is simpler, more convenient and more intuitive, and the usability is improved;
2. different requirements of different users on type mapping can be met, and the expansibility is good;
3. the naming specifications of different users for different levels of the project are met, and good flexibility is embodied;
4. the configuration information is effectively managed, one-time configuration and permanent use are easily realized, the development cost is saved, and the production efficiency is improved.
The following describes the code file generation apparatus provided by the present invention, and the code file generation apparatus described below and the code file generation method described above may be referred to in correspondence with each other.
Fig. 9 is a schematic structural diagram of a code file generation apparatus provided in the present invention. As shown in fig. 9, the apparatus includes a configuration information obtaining module 10, a table information obtaining module 20, an instantiation object obtaining module 30, and a code file generating module 40, where: the configuration information obtaining module 10 is configured to: acquiring configuration group information, and acquiring corresponding configuration information according to the configuration group information; wherein the configuration information comprises a package path configuration and a file naming configuration of at least one code file; the table information obtaining module 20 is configured to: acquiring description information of a data table and information of data fields in the data table; the instantiated object acquisition module 30 is configured to: obtaining a package path and a file name according to the package path configuration, the file name configuration and the description information of the data table; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; the code file generation module 40 is configured to: and combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file.
The code file generation device acquires configuration group information, acquires corresponding configuration information comprising package path configuration and file naming configuration of at least one code file according to the configuration group information, acquires description information of a data table and information of data fields in the data table, and acquires package paths and file names according to the package path configuration, the file naming configuration and the description information of the data table; the method comprises the steps of generating an instantiation object corresponding to configuration information based on package paths, file naming, description information of a data table and information of data fields, combining the instantiation object with a code template corresponding to a code file to generate a corresponding code file, and performing configuration management on common operations, so that the subsequent selection and maintenance cost is reduced, the effective management of the configuration information is realized, the expansibility, the flexibility, the usability and the universality of code generation are enhanced, and the code generation efficiency is improved.
According to the code file generation device provided by the invention, the configuration information further comprises type mapping configuration; the instantiated object obtaining module 30, when configured to generate an instantiated object corresponding to the configuration information based on the package path, the file name, the description information of the data table, and the information of the data field, is specifically configured to: performing data type conversion on the data field according to the type mapping configuration; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; and the information of the data field comprises the name of the data field and the converted data type.
According to the code file generation device provided by the invention, the data type of the data field in the data table is converted according to the type mapping configuration to generate the instantiation object, so that the flexible configuration of the data type mapping is improved, and the expansibility is improved.
According to the code file generating apparatus provided by the present invention, when the code file generating module 40 is configured to combine the instantiation object with the code template corresponding to the code file to generate the corresponding code file, it is specifically configured to: obtaining a method screening result of the code template of a corresponding level of a code file; wherein the screening result of the method comprises a selected method and an unselected method; and combining the instantiation object with the code template corresponding to the code file, and generating the corresponding code file aiming at the selected method.
According to the code file generation device provided by the invention, the corresponding code file is generated by aiming at the selected method through the method screening result of obtaining the code template of the corresponding hierarchy, so that the flexibility of code file generation is further improved.
According to a code file generating apparatus provided by the present invention, before the code file generating module 40 is configured to combine the instantiation object with the code template corresponding to the code file to generate the corresponding code file, it is further configured to: and acquiring a code template selection result, and acquiring the code template according to the code template selection result.
According to the code file generation device provided by the invention, the code template is obtained according to the code template selection result, and the instantiation object is combined with the code template corresponding to the code file to generate the corresponding code file, so that the flexibility of code file generation is further improved.
According to a code file generating apparatus provided by the present invention, before the configuration information obtaining module 10 is configured to obtain the configuration group information, the configuration information obtaining module is further configured to: displaying a code generation configuration interface, wherein the code generation configuration interface comprises at least one of a data definition language information input sub-interface, a configuration group selection sub-interface, a template selection sub-interface and a method selection sub-interface; the data definition language information input sub-interface is used for receiving input data definition language information, and the data definition language information is used for analyzing and obtaining description information of the data table and information of the data fields in the data table; the configuration group selection sub-interface is used for acquiring the configuration group information; the template selection sub-interface is used for acquiring the code template selection result; the method selection sub-interface is used for obtaining the method screening results of the code templates of different levels.
According to the code file generation device provided by the invention, the code generation configuration interface comprising at least one of the data definition language information input sub-interface, the configuration group selection sub-interface, the template selection sub-interface and the method selection sub-interface is arranged, so that the operation is simpler, more convenient and more intuitive, and the usability is improved.
According to the code file generation device provided by the invention, the description information of the data table comprises a data table name; the instantiated object acquisition module 30 is further configured to: in the package path configuration and/or the file naming configuration, representing the data table name by using a preset variable; the instantiated object obtaining module 30 is specifically configured to, when configured to obtain the package path and the file name according to the package path configuration, the file name configuration, and the description information of the data table: judging whether the packet path configuration contains the preset variable or not, if so, replacing the preset variable in the packet path configuration with the data table name or with a character obtained by converting the data table name through a preset first format, and obtaining the packet path; if not, directly configuring the packet path as the packet path; judging whether the file naming configuration contains the preset variable or not, if so, replacing the preset variable in the file naming configuration with the data table name or replacing the preset variable with a character obtained after the data table name is subjected to preset second format conversion, and obtaining the file naming; if not, the file naming configuration is directly used as the file naming.
According to the code file generation device provided by the invention, the preset variable is used for representing the name of the data table in the package path configuration and/or the file naming configuration, and the preset variable is replaced by the name of the data table or the character string obtained after the format conversion is carried out on the name of the data table, so that the package path and the file naming are obtained, and the flexibility of the package path and the file naming setting is improved.
According to a code file generating apparatus provided by the present invention, after the code file generating module 40 is configured to generate the corresponding code file, it is further configured to: and respectively generating corresponding folders for the at least one code file according to the corresponding package paths, compressing and packaging the code files, and storing the compressed packages under a preset path.
The code file generation device provided by the invention has the advantages that the at least one code file is compressed and packaged after being respectively generated into the corresponding folders according to the corresponding package paths, and the compressed packages are stored under the preset paths, so that the practicability is improved.
Fig. 10 is a schematic structural diagram of an electronic device provided in the present invention, and as shown in fig. 10, the electronic device may include: a processor (processor)1010, a communication Interface (Communications Interface)1020, a memory (memory)1030, and a communication bus 1040, wherein the processor 1010, the communication Interface 1020, and the memory 1030 communicate with each other via the communication bus 1040. Processor 1010 may call logic instructions in memory 1030 to perform a code file generation method comprising: acquiring configuration group information, and acquiring corresponding configuration information according to the configuration group information; wherein the configuration information comprises a package path configuration and a file naming configuration of at least one code file; acquiring description information of a data table and information of data fields in the data table; obtaining a package path and a file name according to the package path configuration, the file name configuration and the description information of the data table; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; and combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file.
Furthermore, the logic instructions in the memory 1030 can be implemented in software functional units and stored in a computer readable storage medium when the logic instructions are sold or used as independent products. 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.
In another aspect, the present invention also provides a computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions which, when executed by a computer, enable the computer to perform the code file generation method provided by the above methods, the method comprising: acquiring configuration group information, and acquiring corresponding configuration information according to the configuration group information; wherein the configuration information comprises a package path configuration and a file naming configuration of at least one code file; acquiring description information of a data table and information of data fields in the data table; obtaining a package path and a file name according to the package path configuration, the file name configuration and the description information of the data table; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; and combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file.
In yet another aspect, the present invention also provides a non-transitory computer-readable storage medium having stored thereon a computer program, which when executed by a processor is implemented to perform the code file generation methods provided above, the method comprising: acquiring configuration group information, and acquiring corresponding configuration information according to the configuration group information; wherein the configuration information comprises a package path configuration and a file naming configuration of at least one code file; acquiring description information of a data table and information of data fields in the data table; obtaining a package path and a file name according to the package path configuration, the file name configuration and the description information of the data table; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; and combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A code file generation method, comprising:
acquiring configuration group information, and acquiring corresponding configuration information according to the configuration group information; wherein the configuration information comprises a package path configuration and a file naming configuration of at least one code file;
acquiring description information of a data table and information of data fields in the data table;
obtaining a package path and a file name according to the package path configuration, the file name configuration and the description information of the data table; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field;
and combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file.
2. The code file generation method of claim 1, wherein the configuration information further includes a type mapping configuration; generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table, and the information of the data field, specifically including:
performing data type conversion on the data field according to the type mapping configuration;
generating an instantiation object corresponding to the configuration information based on the packet path, the file name, the description information of the data table and the information of the data field; and the information of the data field comprises the name of the data field and the converted data type.
3. The method according to claim 1, wherein the generating the corresponding code file by combining the instantiation object with the code template corresponding to the code file specifically comprises:
obtaining a method screening result of the code template of the corresponding level of the code file; wherein the screening result of the method comprises a selected method and an unselected method;
and combining the instantiation object with the code template corresponding to the code file, and generating the corresponding code file aiming at the selected method.
4. The method according to claim 3, wherein before the step of combining the instantiation object with the code template corresponding to the code file to generate the corresponding code file, the method further comprises:
and acquiring a code template selection result, and acquiring the code template according to the code template selection result.
5. The code file generation method of claim 4, wherein prior to said obtaining configuration group information, the method further comprises:
displaying a code generation configuration interface, wherein the code generation configuration interface comprises at least one of a data definition language information input sub-interface, a configuration group selection sub-interface, a template selection sub-interface and a method selection sub-interface;
the data definition language information input sub-interface is used for receiving input data definition language information, and the data definition language information is used for analyzing and obtaining description information of the data table and information of the data fields in the data table; the configuration group selection sub-interface is used for acquiring the configuration group information; the template selection sub-interface is used for acquiring the code template selection result; the method selection sub-interface is used for obtaining the method screening results of the code templates of different levels.
6. The code file generation method according to claim 1, wherein the description information of the data table includes a data table name; the method further comprises the following steps: in the package path configuration and/or the file naming configuration, representing the data table name by using a preset variable; the obtaining of the package path and the file name according to the package path configuration, the file name configuration and the description information of the data table specifically includes:
judging whether the packet path configuration contains the preset variable or not, if so, replacing the preset variable in the packet path configuration with the data table name or with a character obtained by converting the data table name through a preset first format, and obtaining the packet path; if not, directly configuring the packet path as the packet path;
judging whether the file naming configuration contains the preset variable or not, if so, replacing the preset variable in the file naming configuration with the data table name or replacing the preset variable with a character obtained after the data table name is subjected to preset second format conversion, and obtaining the file naming; if not, the file naming configuration is directly used as the file naming.
7. The code file generation method of claim 1, wherein after said generating the corresponding code file, the method further comprises:
and respectively generating corresponding folders for the at least one code file according to the corresponding package paths, compressing and packaging the code files, and storing the compressed packages under a preset path.
8. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the code file generation method according to any of claims 1 to 7 are implemented when the processor executes the program.
9. A non-transitory computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the code file generation method according to any one of claims 1 to 7.
10. A computer program product comprising computer programs/instructions, characterized in that the computer programs/instructions, when executed by a processor, implement the steps of the code file generation method according to any of claims 1 to 7.
CN202110746081.XA 2021-07-01 2021-07-01 Code file generation method, electronic device, storage medium, and program product Pending CN113760352A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110746081.XA CN113760352A (en) 2021-07-01 2021-07-01 Code file generation method, electronic device, storage medium, and program product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110746081.XA CN113760352A (en) 2021-07-01 2021-07-01 Code file generation method, electronic device, storage medium, and program product

Publications (1)

Publication Number Publication Date
CN113760352A true CN113760352A (en) 2021-12-07

Family

ID=78787530

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110746081.XA Pending CN113760352A (en) 2021-07-01 2021-07-01 Code file generation method, electronic device, storage medium, and program product

Country Status (1)

Country Link
CN (1) CN113760352A (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050155016A1 (en) * 2004-01-13 2005-07-14 Joachim Bender Flexible code generation
CN102375743A (en) * 2011-10-20 2012-03-14 北京金和软件股份有限公司 SOA(Service-Oriented Architecture) system development method based on model and template
CN106293664A (en) * 2015-05-27 2017-01-04 交通银行股份有限公司 Code generating method and device
CN107368346A (en) * 2017-07-06 2017-11-21 万惠投资管理有限公司 A kind of code generating method and device based on metadata and script engine
CN109710236A (en) * 2018-12-30 2019-05-03 北京字节跳动网络技术有限公司 Business development and implementation method, device, platform and medium based on shared service
CN110032369A (en) * 2019-04-24 2019-07-19 成都市映潮科技股份有限公司 A kind of code automatic generation method, device and medium
CN111324343A (en) * 2020-02-20 2020-06-23 支付宝(杭州)信息技术有限公司 Code generation method and device
CN112052038A (en) * 2020-09-09 2020-12-08 云账户技术(天津)有限公司 Method and device for generating front-end interface
WO2021052260A1 (en) * 2019-09-20 2021-03-25 第四范式(北京)技术有限公司 Method and device for automatically generating feature computational code
CN113050946A (en) * 2021-04-29 2021-06-29 成都新希望金融信息有限公司 Method and device for generating website application system, electronic equipment and storage medium

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050155016A1 (en) * 2004-01-13 2005-07-14 Joachim Bender Flexible code generation
CN102375743A (en) * 2011-10-20 2012-03-14 北京金和软件股份有限公司 SOA(Service-Oriented Architecture) system development method based on model and template
CN106293664A (en) * 2015-05-27 2017-01-04 交通银行股份有限公司 Code generating method and device
CN107368346A (en) * 2017-07-06 2017-11-21 万惠投资管理有限公司 A kind of code generating method and device based on metadata and script engine
CN109710236A (en) * 2018-12-30 2019-05-03 北京字节跳动网络技术有限公司 Business development and implementation method, device, platform and medium based on shared service
CN110032369A (en) * 2019-04-24 2019-07-19 成都市映潮科技股份有限公司 A kind of code automatic generation method, device and medium
WO2021052260A1 (en) * 2019-09-20 2021-03-25 第四范式(北京)技术有限公司 Method and device for automatically generating feature computational code
CN111324343A (en) * 2020-02-20 2020-06-23 支付宝(杭州)信息技术有限公司 Code generation method and device
CN112052038A (en) * 2020-09-09 2020-12-08 云账户技术(天津)有限公司 Method and device for generating front-end interface
CN113050946A (en) * 2021-04-29 2021-06-29 成都新希望金融信息有限公司 Method and device for generating website application system, electronic equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
刘于新;姚凯学;许道云;: "基于模板的.Net三层架构的代码自动生成", 计算机技术与发展, no. 08, pages 13 - 16 *

Similar Documents

Publication Publication Date Title
CN108279932B (en) Method and device for dynamically configuring user interface of mobile terminal
US9454619B2 (en) Layered user interface
CN105511873B (en) User interface control display method and device
CN111666526A (en) Page generation method, device, equipment and storage medium
CN109542445A (en) A kind of method and apparatus that Android plug-in unit melts hair
CN112835560A (en) WEB multi-terminal low-code intelligent software development platform
CN104035772A (en) Static analysis based source code multi-versionfunction call relation difference identification method
US9720656B2 (en) Method and apparatus for enabling agile development of services in cloud computing and traditional environments
CN107766042A (en) A kind of visual data manager and device of the model file based on CSAR
CN110007994B (en) Software internationalization method and system
CN114912897A (en) Workflow execution method, workflow arrangement method and electronic equipment
CN113760352A (en) Code file generation method, electronic device, storage medium, and program product
CN115993966A (en) Application development system and method
Xiaohua et al. Design and implementation of OpenDayLight manager application
US6351842B2 (en) Method for producing computer-controlled services
CN114281539A (en) Resource allocation method, system and storage medium
CN113778421A (en) Method and equipment for generating service code
CN115617333A (en) Data updating method and device, electronic equipment and storage medium
CN112948264A (en) Test task execution method, device, system, storage medium and electronic device
CN112486378A (en) Graph generation method, device, terminal and storage medium
CN116360797B (en) DSL-based security baseline creation method, system, device and medium
CN111240679B (en) Page development method and system
CN116185385A (en) Visual interface management method, system, terminal and storage medium
WO2023172327A1 (en) Generation and consumption of templates based on source code examples
CN116540983A (en) Logic configuration design method, device and platform

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