CN114281331A - Method and device for generating front-end and back-end code files for accessing database - Google Patents

Method and device for generating front-end and back-end code files for accessing database Download PDF

Info

Publication number
CN114281331A
CN114281331A CN202111611427.1A CN202111611427A CN114281331A CN 114281331 A CN114281331 A CN 114281331A CN 202111611427 A CN202111611427 A CN 202111611427A CN 114281331 A CN114281331 A CN 114281331A
Authority
CN
China
Prior art keywords
template
information
file
view object
code
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
CN202111611427.1A
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.)
WeBank Co Ltd
Original Assignee
WeBank 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 WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202111611427.1A priority Critical patent/CN114281331A/en
Publication of CN114281331A publication Critical patent/CN114281331A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to the field of financial technology (Fintech), and discloses a method and a device for generating a front-end code file and a back-end code file for accessing a database, which are used for reading a database configuration file; aiming at any data table in each data table, creating a table view object of the data table according to the table configuration information of the data table and the table description information of the data table; and generating code files aiming at the front end and the back end of the data table according to the table view object and a preset front end code template and a preset back end code template. In the method, after a developer finishes the design of a basic database table, all basic codes required by a project can be generated through simple configuration, not only codes of general database operation are covered, but also codes of corresponding check notes, enumeration value inspection, addition and deletion of check operations and the like can be generated according to specific design, annotation information, index design and the like of database fields. The workload of developers is greatly reduced, and the development period of a service system is shortened.

Description

Method and device for generating front-end and back-end code files for accessing database
Technical Field
The embodiment of the application relates to the field of financial technology (Fintech), in particular to a method and a device for generating a front-end code file and a back-end code file for accessing a database.
Background
With the development of computer technology, more and more technologies (such as cloud computing, big data or block chains) are applied in the financial field, and the traditional financial industry is gradually shifting to the financial technology. For example, for a financial department of a bank, if a report related to tax is made only by manpower, it is obviously not able to meet the demand for a large environment where mass data currently exists, so the bank generally needs to develop a corresponding counter system to perform statistical calculation and declaration of tax. Because tax declaration generally has the characteristics of multiple taxes, complicated declaration form and complicated data types, the quantity of related statistical data tables and various calculation tables is very remarkable for a certain tax. In general, one data table in a database corresponds to one front-end page, and after a developer designs each database table structure for implementing a counter system, the developer still needs to manually write the following front-end code files corresponding to each database table, including: a Data Transfer Object (DTO) file corresponding to a database table, a mapper file operating a database interface, a service file providing actual service implementation for a backend interface, a controller file providing a backend interface, and an vue file providing a front-end style and an operation page.
In view of the factors of complex database table structure and huge table number, the above-described manner of relying on a developer to manually write the front-end code file and the back-end code file of the counter system is not only cumbersome, but also is prone to errors. For this reason, developers currently use some automatic code generation tools to generate front-end and back-end code files, and the following are common:
mybatis-generator, a dedicated automatic code generation tool for mybatis. After providing the configuration information and table information of the corresponding database, the code required for executing the mabytis, such as mapper. java, mapper. xml and DTO files, can be automatically generated according to the table structure in the database.
mybatis-plus generator is an automatic code generation tool for mybatis upgrade. On the basis of mybatis-generator, a controller, a service interface and a serviceImpl file can be generated, and the packet path of each file can be specified.
For automatic generation of front-end code, the vscode provides a plug-in that can generate a blank vue template, and there are some page generation tools of the drag operation class on the market today.
However, the above-mentioned solution for generating the front-end and back-end code files based on the automatic code generation tool has the following disadvantages:
1. the existing automatic code generation tools are complex to use in order to meet the universality. For example, mybatis-generator needs to use xml file configuration, and needs to specify a path and a class name for a file corresponding to each database table, and can only generate a frame part code. In addition, the dragging type automatic code generation tool applied to the front end needs a developer to manually input required fields when in use, which is obviously not friendly to various wide tables of the tax system.
2. The existing automatic code generation tool can only generate basic codes according to field names and field types of tables, but does not fully process information such as field limitation, nullability, main keys and indexes provided in table information, and also needs developers to manually write codes for data verification and general file operation of a counter system, so that a large amount of repetitive work reduces development efficiency.
Therefore, there is a need for an efficient method for automatically generating front and back end code files for counter systems.
Disclosure of Invention
The application provides a method and a device for generating front-end and back-end code files for accessing a database, which are used for efficiently and automatically generating the front-end and back-end code files for a counter system.
In a first aspect, an embodiment of the present application provides a method for generating a front-end code file and a back-end code file for accessing a database, where the method includes: reading a database configuration file; the database configuration file comprises database connection information and table configuration information of each data table; the table configuration information is provided with various configuration information of front and back end code files for generating the data table; aiming at any data table in the data tables, acquiring the table description information of the data table through the database connection information; wherein, the table description information is provided with various attribute information describing the data table; creating a table view object of the data table according to the table configuration information of the data table and the table description information of the data table; the table view objects comprise column view objects, at least one column view object comprises annotation information of column fields, and the annotation information is used for setting limits on field values of the column fields in the front-end and back-end interaction process; and generating code files aiming at the front end and the rear end of the data table according to the table view object and a preset front end code template and a preset rear end code template.
In the above scheme, for a business system, after a developer completes the design of a basic database table, that is, corresponding table description information is designed for any one database table, all basic codes required by a project can be generated through simple configuration (including a database configuration file and table configuration information), so that not only codes of general database operation are covered, but also codes of corresponding check notes, enumeration value check, addition, deletion, modification, check operation and the like can be generated according to specific design, annotation information, index design and the like of a database field. The workload of developers is greatly reduced, and the development period of a service system is shortened.
In one possible implementation method, the creating a table view object of the data table according to the table configuration information of the data table and the table description information of the data table includes: creating an initial table view object; the initial table view object comprises a plurality of pending members; for any column field in a column member of the plurality of pending members, creating a column view object for the column field; if the table description information of the data table and/or the table configuration information of the data table has annotation information of the column field, adding an indication corresponding to the annotation information to the column view object, thereby generating the table view object of the data table.
In the scheme, all information of each data table for constructing the service system can be acquired by creating the table view object; particularly, by creating a column view object for any column field in column members in the table view object, the obtained annotation information can be added to the corresponding column view object after the annotation information of the column field is obtained, so that corresponding annotations can be automatically injected into fields needing to be specially set when front and back end code files are generated, for example, requirements on setting field nullability, field verification and field value enumeration can be met.
In one possible implementation, the adding the indication corresponding to the annotation information to the column view object includes: if the dictionary information of the column field is acquired from the table description information of the data table, adding dictionary annotation instructions in the column view object, and adding the dictionary annotation instructions and the dictionary information into a data dictionary; the dictionary annotation indicates dictionary information for retrieving the column field from the data dictionary.
In the above scheme, for some fields in some data tables in the database, many complex chinese descriptions used by the business system will be stored in the database in a fixed coding form, and only the front end displays the corresponding description information. For the field, the format of { enumerated value 1-meaning, enumerated value 2-meaning and enumerated value 3-meaning } is preset in the field annotation of the table description information of the database table in the scheme, so that when the annotation information in the field information is traversed, if a character string in the format is found, the annotation of the field needs to be added in the column view object corresponding to the field, namely dictionary annotation indication is added, and further when the field is used, the description information input by a user can be correspondingly converted into the enumerated value stored in the database, and the enumerated value stored in the database is converted into the description information which can be understood by the user after query.
In one possible implementation, the adding the indication corresponding to the annotation information to the column view object includes: if the index information of the column field is acquired from the table description information of the data table, an index annotation indication is added to the column view object; and if the index information is a primary key index, setting information of a primary key strategy member in the table view object.
In the above scheme, for any data table in the database, the information that needs to be transmitted out of the data table may be displayed through a plurality of fields, and the fields will need to meet the relevant requirements when filling the corresponding values. The requirements set for each field can be expressed as perfecting the information of each column view object in the table view object, and for any field, except that the table description information of the field in the data table can be read, and writing the acquired annotation requiring the configuration of the field in advance in the column view object corresponding to the field, particularly, the method can be written in a comment list of the column view object, and also comprises the steps of determining whether the comment of the field with the same name can be further perfected or not from the viewpoint of index information in the table description information, therefore, the field annotation in the column view object corresponding to each field is the most perfect, and when the code files at the front end and the rear end of the data table generated based on the table view object are applied, each field in the data table can achieve each expected function of a business system developer in the design of the data table.
In one possible implementation, the adding the indication corresponding to the annotation information to the column view object includes: if the check information of the column field is acquired from the table description information of the data table and/or the table configuration information of the data table, adding a check annotation indication in the column view object; the check annotation indicates a check class used to indicate the column field.
In the above scheme, for any data table in the database, the information that the data table needs to be transmitted out may be displayed through a plurality of fields, and when the fields are filled with corresponding values, the fields need to meet the relevant requirements, such as whether the fields are empty, whether the functions of uploading, downloading and calculation are supported, or other rules for field verification customized by a developer. Therefore, when information of each column view object in the column view object is improved, for any field, not only can table description information of the field in the data table be read, and the obtained comment requiring configuration of the field in advance is written in the column view object corresponding to the field, specifically, the comment list of the column view object, but also whether the comment of the field with the same name can be further improved is determined from the viewpoint of table configuration information of the data table, so that field comments in the column view object corresponding to each field are improved most, and when a code file at the front end and the rear end of the data table generated based on the table view object is applied, each field in the data table can achieve each expected function of a business system developer when the data table is designed.
In a possible implementation method, the generating, according to the table view object and a preset front-end and back-end code template, code files for front ends and back ends of the data table includes: loading the table view object to a back-end DTO file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end DTO code file; loading the table view object to a back-end POJO file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end POJO code file; loading the table view object to a back-end Mapper file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Mapper code file; loading the table view object to a back-end Service file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Service code file; and loading the table view object to a front-end and back-end connected Controller file template contained in the front-end and back-end code templates in the table configuration information through a template engine to generate a front-end and back-end Controller code file.
In the above scheme, for a data table in the database, since the key information required to be filled into the code file can be encapsulated by the table view object and some dependent related classes are provided in the JAR, the code files at the front and back ends of the data table can be generated by using the template engine, i.e., the basic data model required by each file is introduced into the interface of the template engine.
In a possible implementation method, the loading, by a template engine, the table view object to a back-end DTO file template included in a front-end code template and a back-end code template in the table configuration information to generate a back-end DTO code file includes: for each column view object, based on a back-end DTO file template, when a primary key field of the column view object is consistent with a primary key field of a table view object, generating a back-end DTO code with primary key annotation; generating a back-end DTO code with value annotation aiming at the field with value constraint; generating a back-end DTO code with dictionary annotation indication aiming at the field with the dictionary annotation indication; the loading, by the template engine, the table view object to a back-end POJO file template included in a front-end code template and a back-end code template in the table configuration information to generate a back-end POJO code file includes: generating a back-end POJO code with index information by aiming at index annotation indication in the table view object through a back-end POJO file template; loading the table view object to a back-end Mapper file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Mapper code file, wherein the generating comprises: generating a back-end Mapper code of database operation with index information by a back-end Mapper file template aiming at index annotation indication in the table view object; loading the table view object to a back-end Service file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Service code file, wherein the method comprises the following steps: generating a back-end Service code with index information and an uploading and downloading function through a back-end Service file template aiming at the index annotation indication in the table view object and the uploading and downloading function indication in the table view object; the loading, by the template engine, the table view object to a Controller file template connecting a front end and a back end, which is included in the front-back end code template in the table configuration information, and generating a front-end Controller code file, includes: and aiming at the uploading and downloading function indication in the table view object, generating a front-end and back-end Controller code with an HTTP interface through a Controller file template connected with the front end and the back end.
In the above scheme, a method for generating the code files at the front and back ends of a data table is specifically set forth, and finally, by operating the code files at the front and back ends of the data table, the automatic generation of the data table at the front and back ends can be realized, and the automatically generated data table can meet the requirements of business system developers on the general restrictions of the data and the requirements on the personalized restrictions of some fields in the data table.
In a second aspect, an embodiment of the present application provides an apparatus for generating a front-end code file for accessing a database, where the apparatus includes: the reading unit is used for reading the database configuration file; the database configuration file comprises database connection information and table configuration information of each data table; the table configuration information is provided with various configuration information of front and back end code files for generating the data table; the acquisition unit is used for acquiring the table description information of the data table through the database connection information aiming at any one data table in each access data table; wherein, the table description information is provided with various attribute information describing the data table; the creating unit is used for creating a table view object of the data table according to the table configuration information of the data table and the table description information of the data table; the table view objects comprise column view objects, at least one column view object comprises annotation information of column fields, and the annotation information is used for setting limits on field values of the column fields in the front-end and back-end interaction process; and the generating unit is used for generating each code file aiming at the front end and the back end of the data table according to the table view object and a preset front end code template and a preset back end code template.
In a third aspect, an embodiment of the present application provides a computing device, including:
a memory for storing program instructions;
and the processor is used for calling the program instructions stored in the memory and executing the implementation method of the first aspect according to the obtained program.
In a fourth aspect, the present application provides a computer-readable storage medium storing computer-executable instructions for causing a computer to perform the method according to any one of the first aspects.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic flowchart illustrating an implementation of automatically generating a front-end code file and a back-end code file according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a process for constructing a table view object according to an embodiment of the present disclosure;
fig. 3 is a schematic diagram of a method for generating a front-end code file and a back-end code file for accessing a database according to an embodiment of the present application;
fig. 4 is a schematic diagram of a device for generating a front-end code file and a back-end code file for accessing a database according to an embodiment of the present application;
fig. 5 is a schematic diagram of a computing device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be described in further detail with reference to the accompanying drawings, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all embodiments. 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 application.
Taking the financial department of a bank as an example, in the process of making statement data related to tax regulated by the state, various statement sheets can be made by constructing a counter system, so that the burden of related financial staff who originally needs to make statement sheets manually is reduced to a great extent. However, with the current solution of generating a counter system by running front and back end codes corresponding to the counter system generated based on an automated code generation tool, it is still impossible to make corresponding user-desired settings for some fields in the data table that need to be specially defined, resulting in a relatively single function of the generated counter system. In other words, for a counter system generated after running based on front and back end codes generated by an automatic code generation tool, the counter system cannot be well combined with business scene requirements at present.
In view of the above technical problems, the present application provides the following solutions. Based on the scheme, the effect of overcoming the technical problems can be achieved.
For example, taking the financial department of a bank as an example, performing tax declaration is one of the work contents of related financial staff. For example, the financial staff can achieve the purpose of calculating various declaration forms required by the tax bureau by using the designed counter system. The calculation of the statement table is obtained by carrying out a series of complex operations on basic detail data acquired in a certain period; meanwhile, in order to meet the account checking requirement and the related tax law requirement, a set of intermediate table is also required to be stored for each module data of the statement, and the intermediate table is used for recording intermediate result data in the calculation process. Therefore, from the perspective of data evolution, the data tables in the database can be classified, including the collected data table, the intermediate result table, and the valid result table.
Because the types of the data tables stored in the database for implementing the counter system are many, from the business aspect, the functions that the bank side wants to be able to implement the counter system may include at least the following:
1. and (3) checking and prompting the input information: such as mandatory items, field format requirements, data range requirements, etc.;
2. and (3) maintaining the input information: single entry, modification and deletion and batch entry in a file form are supported;
3. multi-way display of service information: page display, attachment export, email notification, etc., and multi-condition queries;
4. and generating, adjusting and recalculating the service result data.
Because the counter system implements the business function, which is a process of converting the business operation into a change of the database table, for the above several functions that the counter system is expected to implement, the following general operations can be mapped to the database table:
1. the DTO data field verification during data writing comprises non-null verification, enumerated value verification, numerical range verification, character string length verification and service self-defined verification;
2. conditional query, Excel uploading and exporting of table data;
3. conditional query, addition and modification of single data;
4. recalculating the table data according to the accounting period;
5. data encoding and conversion of display text.
In the embodiment of the present application, taking an example that a business system, a counter system, is developed based on Java language, the counter system to be developed is further constrained by the following points:
1. the library name, the table name, the field and the index name are combined by using lower case letters, numbers and underlines in a unified way, the beginning of the number is forbidden, and only the number is forbidden between the two underlines;
2. the primary key index name is pk _ field name, the unique index name is uk _ field name, and the common index name is idx _ field name;
3. the digital type prohibits using float and double, the digital enumeration value uses tinyint signed, and the other types use decimal;
4. the database table and the field detail must have annotations;
5. table has three fields: id, created _ by, created _ date, last _ modified _ by, last _ modified _ date. id must be the primary key, support the bigint assigned type of autonomic key and the varchar type of custom primary key. Both the created _ data and last _ modified _ data are TIMESTAMP (3) types. creating _ by and last _ modified _ by are system login users;
6. an enumerated value field, the annotated format being "field annotation, { enumerated value 1-meaning, enumerated value 2-meaning, enumerated value 3-meaning }";
7. setting a table unique key with a service main key;
8. the business meaning and the input data format of the fields with the same name are required to be consistent, and the same business field should keep the same field name in different tables.
Based on the constraints made on the counter system to be generated, the application provides a method for generating front and back end code files based on a mybatis frame, a springboot frame and an vue frame.
As shown in fig. 1, a schematic flow chart for automatically generating a front-end code file and a back-end code file provided in an embodiment of the present application is provided for any data table constituting a counter system, and includes the following steps:
step 101, reading a database configuration file.
In this step, the database configuration file may be referred to as database. The configuration items of database and properties are shown in table 1 below:
field(s) Description of the invention
diver_name Database type
url Database JDBC connection string
username User name
password Cipher code
tables Table name
Table 1 configuration items of database
Wherein, the diver _ name represents the type of the database, the url represents the data source of the counter system constructed this time, that is, the address information of the database that needs to be used, the username and password represent the authentication information when the database is used, and the tables represent the table information of the relevant data table in the database that the counter system needs to be used. The embodiment of the present application may provide the following two ways of configuring tables:
mode 1: only table names are provided, wherein the table names are divided using a designated divider, and table configuration information of each data table is subject to common parameter configuration files (profiles). Such as:
tables=table_a,table_b,table_c
mode 2: parameters can be designated for a single data table by configuring the json character string, so that the effect of covering the configuration of the parameters with the same name in the config. Such as:
tables={table=table_a,db_table_id=org_id,webroot_package=../src/},{table=table_b,db_table_id=org_id}}
the configuration items of the properties are as follows:
Figure BDA0003435039320000111
Figure BDA0003435039320000121
table 2 configuration items of properties
For the configuration entry db _ filtered _ indices in properties: the configuration item is used for configuring the mapping relationship of the field and the annotation. According to the constraint of the field with the same name in the service system, appointed notes can be added according to the field name and used for verification, data identity processing and the like. The configuration mode can be json character strings, a field can be configured with a plurality of annotations, and the sequence of generating the annotations is subject to the configuration sequence. The annotation class supports annotations in hibernate-identifier, javax. identifier, springboot and the annotation under the annotation package of the present application. If annotation is needed under other paths, the method can be realized by writing the full path of the class. For example, in a counter system, a time period is often taken as a billing concept, a monthly billing period and a quarterly billing period are commonly used, corresponding monthioperiod and quaterPeriod fields must satisfy a certain format, and for an actually existing month or quarter, for example, a value under the monthioperiod field must be an expression of a month, but not an expression of a year, and an expressed month must be between 12 values of 1 month to 12 months, but cannot be a value except the 12 values of 1 to 12, so that for the monthioperiod field, on one hand, a custom limit of the month expression thereof needs to be set, and on the other hand, a value of each month which can be enumerated needs to be set. Db _ filtered _ indications, shown below, may be embodied in the relationship of the monththiod field to the custom check note:
db_filed_annotations={filed=month_period,annotations=MonthValidate,Enum Validate}
and 102, reading the information of the database table fields in the database configuration file, and generating a database table list.
That is, by reading the value corresponding to the tables field shown in table 1, a database table list can be generated.
Through the steps, the data tables needed to be used by the counter system can be sequenced, the initial table view objects corresponding to the data tables are established for the data tables in sequence, and the table view objects of the data tables are obtained by perfecting the initial table view objects of the data tables, so that the problems of repeated operation and missing operation on the data tables in the operation process can be avoided when front and rear end code files corresponding to the data tables are generated for the data tables needed to be used in the later period.
Step 103, aiming at any data table in the database table list, an initial table view object corresponding to the data table is created based on the table name of the data table, and the table configuration information and the table description information of the data table are obtained through the database configuration file, so that the initial table view object is perfected and the table view object of the data table is obtained.
As shown in fig. 2, a schematic diagram of a table view object constructing process provided in an embodiment of the present application is provided, where the table view object constructing process shown in fig. 2 is sub-steps of step 103, that is, step 103 may specifically include the steps shown in fig. 2, and the contents are as follows:
step 3.1, using JDBC connection (Java Database Connectivity) to inquire whether the data table exists or not; if yes, executing step 3.2; otherwise, a data table is read again from the database table list, and the step is executed for the new data table.
And 3.2, creating an initial table view object, namely creating a tableVO instance, and respectively writing the busi _ package, webscore _ package, template, db _ table _ id, isUpload, isExport and isComputable information in the table configuration information of the data table into the corresponding undetermined member in the tableVO.
In order to convert the table description information and the table configuration information of the data table in the database into object information capable of being identified, the following tableVO objects are designed in the application:
Figure BDA0003435039320000131
Figure BDA0003435039320000141
for a columnVO object in tableVO, that is, a column view object, it may be used to store field information for generation of subsequent entry and POJO files:
Figure BDA0003435039320000142
wherein, for an indexVO object in tableVO, i.e. an index view object, it may be used to store multi-index information of a data table:
Figure BDA0003435039320000143
Figure BDA0003435039320000151
and 3.3, inquiring the table description information of the data table in information _ schema by using JDBC connection, and writing the table name and the table description into the corresponding member of tableVO.
And 3.4, inquiring field information of the data table in information _ schema by using JDBC connection.
And 3.5, traversing the field information, generating a corresponding columnVO object aiming at each field, and hanging the corresponding columnVO object in a column list of tableVO.
In addition, in this step, when generating a columnVO object according to the field information, the database type and the Java type may be converted according to the following mapping:
database type Java type
varchar java.lang.String
longtext java.lang.String
bigint java.lang.Integer
datetime java.util.Date
int java.lang.Integer
decimal java.math.BigDecimal
tinyint java.lang.Integer
blob byte[]
smallint java.lang.Integer
text java.lang.String
timestamp java.util.Date
date java.util.Date
Step 3.6, determine if column vo field com contains a string in { enumerated value 1-meaning 1, enumerated value 2-meaning 2, enumerated value 3-meaning 3} format. If yes, step 3.7 is executed, otherwise step 3.12 is executed.
Many complex Chinese descriptions used by the business system are stored in a database in a fixed coding form, and are only displayed and converted into corresponding description information at the front end. For example, for the gender field, the user may edit "male/female" when inputting the front end, and the rear end may store the field value input by the user in a corresponding encoding form instead of storing the field value actually input by the user in a database, for example, a preset number "0" may be used to indicate gender male and a preset number "1" may be used to indicate gender female, so that the field value may be stored as "0/1". This type of field is required to be noted in the present scheme in the column notation of the database table in the format of { enumerated value 1-meaning, enumerated value 2-meaning, enumerated value 3-meaning }.
For the above-described scenario of data transformation, embodiments of the present application provide a design of a data dictionary, where: two tables are designed in the database, which are a data dictionary table and a data dictionary detail table respectively and are used for storing the mapping relation of each data dictionary. The data dictionary table is shown in table 3, and the data dictionary list table is shown in table 4.
Field(s) Description of the invention
dict_name Dictionary name
dict_code Dictionary coding
TABLE 3 data dictionary Table
Field(s) Description of the invention
dict_code Dictionary coding
item_value Dictionary entry value
item_text Dictionary entry text
TABLE 4 data dictionary List
The annotation class @ Dict is designed. Acting on the field (field), the field that needs to be transformed from the data dictionary is labeled. The following annotation parameters are provided which may specify the data dictionary code, dictionary entry text.
String dicCode();
String dicText()default"";
At the back end of the server, defining AOP tangent point on the interface (generally interface on controller) which needs to perform data dictionary conversion on the return value, and using the AOP tangent point
@Around("dictPointCut()")
public Object around(ProceedingJoinPoint pjp)
Internal implementation of the interception interface. The processed () obtains the original return value of the interface, and obtains the object T by analyzing the return object. Grabbing all member variables of the T, acquiring DictCode in the annotation for the member containing @ Dict annotation, inquiring a mapping relation of { item _ value and item _ text } from a database, converting item _ value stored by the member into item _ text, and adding the item _ value into the member of the T. In addition, when the front end frequently queries a large amount of data, if dictionary information is looked up from the database each time, the query time is greatly increased, and therefore, in the embodiment of the application, the dictionary information can be stored in the memory of the JVM, and only the dictionary information in the JVM needs to be actively refreshed when the dictionary information of the database changes.
At the front end of the server, in order to convert text input or selected by a user into a value, the embodiment of the application provides a dictionary-specific control JDictSelectTag, packages vue native select controls, and adds a prop option dictCode to specify a data dictionary, so that an item _ text value is shown to the user in the select-option, and the value sent to the back end of the server after the user operates is item _ value.
Step 3.7, add the data dictionary @ Dict annotation to the annotations of columnVO.
In this step, by writing the @ dit annotation into the annotation list entries corresponding to the field columnVO, in subsequent step 104, when generating an entry file corresponding to the data table, add an annotation @ dit (dichcode: $ { po. fieldname }) and an enumeration value check annotation @ enumvlid (target $ { po. fieldname } item. class) to the field $ { po. And when an Vue file corresponding to the data table is generated, replacing the Select control with JDictSelectTag for the internal control of the form item corresponding to $ { po.
And 3.8, generating homonym data dictionary items dim _ name and dim _ code according to the columnVO field name and the field annotation, and splicing the data dictionary items and writing the data dictionary items into insert sentences of a data dictionary table.
Step 3.9, mapping { enumeration value 1-meaning 1, enumeration value 2-meaning 2, enumeration value 3-meaning 3} to data dictionary details (item _ value ═ enumeration value 1, item _ text ═ meaning 1, item _ value ═ enumeration value 2, item _ text ═ meaning 2, item _ value ═ enumeration value 3, item _ text ═ meaning 3), and concatenating the data dictionary details into an insert sentence of the data dictionary details table.
For step 3.8 and step 3.9, it is a way to implement the data dictionary proposed in the embodiment of the present application: i.e. if in step 3.6 it is detected that a string of the form { enumerated value 1-meaning 1, enumerated value 2-meaning 2, enumerated value 3-meaning 3} is contained in column vo. Assuming that the field name is $ { fieldName }, the dml statement that is spliced out for this field in step 3.8 and step 3.9 is as follows:
insert into sys_dict
(dict_code,dict_name)values(‘DICT_${fieldName}’,’filedComment’);
insert into sys_dict_item(dict_code,item_value,item_text)values
('DICT _ $ { fieldName }', 'meaning 1', 'enumerated value 1'),
('DICT _ $ { fieldName }', 'meaning 2', 'enumerated value 2');
step 3.10, insert is written to the dml. sql file under the engineering path.
And 3.11, reading the enumeration template file, transmitting the fieldName and the enumeration value list, generating an enum file, and storing the enum file in a/com/webbank/enum/path of the project engineering.
In this step, the following enumerated template file is read from the system specified path, and the sys _ dit _ item list and the fileName initialized according to the annotation are transmitted into the template file as parameters, so that the $ { fieldName } enum.
Figure BDA0003435039320000181
Step 3.12, determine if tablevo · isuppload or isExport is true. If it is determined to be true, step 3.13 is performed, otherwise step 3.5 is performed.
Step 3.13, append @ Excel annotation to the annotations of columnVO.
Step 3.14, determine if the nullable of columnVO is tube. If it is determined to be true, step 3.15 is performed, otherwise step 3.5 is performed.
Step 3.15, add notNull notes to the exceptions in columnVO according to fieldType.
And step 3.16, after traversing the field Information, utilizing JDBC connection to query the index Information of the data table in Information _ schema.
And 3.17, traversing the index information, generating a corresponding index VO object, namely an index view object, aiming at the index _ name and the index _ comment of each index, and hanging the index view object under the index list of the tableVO.
In this step, when traversing the index, if the index type is PRIMARY key index, setting PRIMARY key field of tableVO as the field of the index. If the primary key field type is int, bigint and the field additional information is auto _ increment, the primary key policy primaryKeyPolicy of tableVO is set to idtype. When generating the entry file in the subsequent step 104, adding a TableID annotation to the member corresponding to the primary key field according to primaryKeyField and primaryKeyPolicy, and setting a TableID annotation policy.
And 3.18, reading all colunmn _ names of the index, searching columns with the same name in a tableVO.
Step 3.19, determine if da _ field _ indices is configured in this field database. If it is determined that it is configured, step 3.20 is performed, otherwise the index information is re-traversed and step 3.17 is performed.
In the counter system, the interactive data at the front end and the back end are transmitted in a format of a defined entity object, and the verification and conversion of the data can be realized by adding member notes on the entity object. The conversion of the data can be achieved by the data dictionary scheme described earlier, adding the @ Dict annotation on the corresponding field. The verification of the data may also be accomplished through member annotation:
1. after the controller layer grabs the entry object, whether a check annotation exists in each member object in the object is analyzed.
2. And finding the check implementation class specified by the check annotation.
3. And transmitting the value of the member to a verification implementation class, and returning a verification result after calling a verification method.
The entry object corresponds to a database table, and if the member of the object has constraints such as non-null, non-null and the like, the corresponding constraint is also set in the database table structure corresponding to the object. The Java check package provides common check annotations for this purpose, such as notblank, notnull, etc. In addition to the check information which can be extracted from the database table structure, the scheme provides self-defined data check. Corresponding special annotations can be set according to the business meaning of a certain data column. As the reporting system often uses a time period as an accounting period concept, a monthly accounting period and a quarterly accounting period are commonly used, and corresponding monththeriod and quaterPeriod fields must satisfy a certain format and are actually existed months or quarters. At this time, a @ MonthPeriod @ QuartPeriod custom check interface can be defined.
For the implementation of the custom check interface, if it is monitored in step 3.14 that a certain field of the data table has non-null constraint in the database, notes such as notBlank and the like are automatically injected into the columnVO object; if the data table is detected to have the corresponding db _ field-annotation configuration in the database configuration file in the step 3.19, automatically adding a corresponding comment to the columnVO object downward from the tableVO; and if the data table is detected to have the uploading and downloading function attributes in the step 3.13, adding @ Excel annotation to all columnVOs under the tableVO.
Step 3.20, the field configuration field is analyzed from the configuration, and the indexes are x, x, x.
And 3.21, searching the corresponding columnVO from tableVO.column according to the field, converting the indices into a list, loading a class < x > object according to the class name x, and writing the class < x > object into the column VO.column list.
And 104, generating code files of the front end and the back end of the data table based on the table view object and the preset front end and back end code templates. The method specifically comprises the following steps:
(1) and generating a DTO (entry) file.
Before the step, all the well-defined comments in columnVO are added in front of the member corresponding to the columnVO, so that the automatic injection of the field comments is realized.
In this step, a freemarker template engine may be used in the embodiment of the present application for automatic generation of a code file. Process (Object dataModel, Writer out) interface can write the data in dataModel into template text and output the template text. The dependent related classes in the automatically generated code file are provided in the dependent jar package, and the key information required to be filled in the code file is basically packaged in the steps. The freemarker template supports simple if-else and list instructions, and can compile simple template files to realize logic judgment and traversal logic. The template file can be generated only by transmitting the basic data model required by each file into the interface. The basic design of the template file is as follows, and according to the content of tableVO, the package path, class name, dependent class and basic code block of each code file are set.
The DTO file can automatically generate member variables corresponding to database columns one by one, add field annotations according to the column annotations, specify table names, package names and table annotations, uniformly use @ data annotations of the logbook to replace the traditional getter and setter methods, and support a serialization interface by default. In addition, check annotations are automatically added according to the design of the database columns. The DTO base template is as follows:
Figure BDA0003435039320000211
when the entity file is generated in the step, the template is generated according to the following logic:
1. traversing a columnVO list of tableVO;
2. for each columnVO:
2.1, adding the member definition statement according to the field name and the field type.
2.2, if the columnVO is consistent with the main key field of tableVO, adding @ TableId annotation before the member definition statement, and determining the type according to the main key strategy.
2.3, if the type of columnVO is decimal, int, read annotation filedComment. Fields with constraints on the range of values can be labeled in the notation in the format max:100, min: -1.0. Maxvalue and minValue are extracted from the annotation. And append the @ DecimalMin @ DecimalMax annotation.
2.4, if the type of columnVO is String, appending a String length check @ ByteSizeValidator annotation according to charmax Length.
2.5, if the annotations list of columnVO is not empty, adding the comments in the list one by one before the columnVO definition statement.
(2) And generating a POJO file
The primary key id column is typically used only to provide a unique label for the data column, and has no business implications per se. The actual database table design also has an actual main key column with business meaning, and due to the introduction of the account period concept, the combination of multiple columns is usually set as a unique index, so that the query performance is improved while the data correctness is ensured. This actual business key is used relatively frequently in business operations, and appears in the entries and return values of many business methods. Some common field combinations are also set as common indexes in order to provide database operation efficiency. To this end, the present solution provides for automatic generation of the combinatorial index POJO. The complexity of the method signature is reduced, part of repeated codes are removed, and the code readability is improved:
in this step, index information indexs is obtained from tableVO, main key information is ignored, other indexes are traversed, and a POJO file is generated for each index, wherein the outline of an index POJO file template is as follows:
Figure BDA0003435039320000221
Figure BDA0003435039320000231
(3) and generating the Mapper file.
The Mapper file inherits a com.BaseMapper.BaseMapper < T > general interface, automatically realizes the addition of table data and the deletion and the modification of a main key, and can also utilize a Wrapper < T > self-defined sql condition. The Mapper base template is as follows:
Figure BDA0003435039320000232
in this step, when the template generates a file, if the tableVO contains an index, the following data searching, modifying, and deleting methods for the index are added to the generated file according to the index name:
Figure BDA0003435039320000233
Figure BDA0003435039320000241
(4) and generating a Service file.
The Service method inherits the com.basoidou.mybatisps.extension.service.impl.serviceimpl general type class and automatically inherits the basic operation of increasing, deleting, modifying and searching aiming at the general type T realized by the class. The Service basic template is as follows:
Figure BDA0003435039320000242
in this step, when a Service file is generated, if the tableVO contains an index, the following method is added to the generated file according to the index name:
Figure BDA0003435039320000243
Figure BDA0003435039320000251
if the isuppload attribute of the tableVO is true, adding an uploading method for the Service file:
int importExcel(File file,String username)
if the isExport attribute bit true of tableVO, adding a downloading method for the Service file:
workbook exportExcel(HttpRequest request,${entityName}object)
(5) and generating a Controller file.
The Controller method inherits the BaseController general type designed by the scheme and encapsulates the logic realization of common interfaces such as page query, addition, modification, deletion, batch operation and the like. The generated actual controller class aiming at the single table automatically replaces the import and return objects of the corresponding interface according to the DTO class. The Controller class is only used for specifying the URL and exposing the interface, and the specific logic of each backend interface is not required to be realized. The Controller base template is as follows:
Figure BDA0003435039320000252
Figure BDA0003435039320000261
in this step, similar to the Service file logic, if the tableVO sets the isuppload or isixport attribute, a corresponding HTTP interface code block is added to the generated file.
(6) And Vue file is generated.
A single sheet corresponds to an Vue file, and the universal page design provides a look-up sheet box, an operation button area and a sheet data display area. Specific value queries to arbitrary columns are supported.
For each front-end code file and each back-end code file to be generated in step 104, the generation order may be set by a user, and is not limited to the generation order provided in this application.
The dml file generated by the process is put in a database for execution, and the counter system code generated by the template is put under an engineering path, so that a multi-table basic counter system supporting the increasing, deleting, modifying and checking of single data, batch operation of data and any condition query of table data can be run.
Therefore, based on the above detailed description of the process of generating the front-end code file and the back-end code file of a data table, the embodiment of the present application provides a method for generating the front-end code file and the back-end code file for accessing a database, as shown in fig. 3, which is a schematic diagram of a method for generating the front-end code file and the back-end code file for accessing a database according to the embodiment of the present application, and the method can be executed by a generating device for accessing the front-end code file of a database, such as a server. The method comprises the following steps:
step 301, reading a database configuration file; the database configuration file comprises database connection information and table configuration information of each data table; the table configuration information is provided with various configuration information of front and back end code files for generating the data table;
step 302, aiming at any data table in the data tables, obtaining table description information of the data table through the database connection information; wherein, the table description information is provided with various attribute information describing the data table;
step 303, creating a table view object of the data table according to the table configuration information of the data table and the table description information of the data table; the table view objects comprise column view objects, at least one column view object comprises annotation information of column fields, and the annotation information is used for setting limits on field values of the column fields in the front-end and back-end interaction process;
and 304, generating code files for the front end and the rear end of the data table according to the table view object and a preset front end and rear end code template.
In the above scheme, for a business system, after a developer completes the design of a basic database table, that is, corresponding table description information is designed for any one database table, all basic codes required by a project can be generated through simple configuration (including a database configuration file and table configuration information), so that not only codes of general database operation are covered, but also codes of corresponding check notes, enumeration value check, addition, deletion, modification, check operation and the like can be generated according to specific design, annotation information, index design and the like of a database field. The workload of developers is greatly reduced, and the development period of a service system is shortened.
Some of the above steps will be described in detail with reference to examples.
In one implementation of step 303, the creating a table view object of the data table according to the table configuration information of the data table and the table description information of the data table includes: creating an initial table view object; the initial table view object comprises a plurality of pending members; for any column field in a column member of the plurality of pending members, creating a column view object for the column field; if the table description information of the data table and/or the table configuration information of the data table has annotation information of the column field, adding an indication corresponding to the annotation information to the column view object, thereby generating the table view object of the data table.
The content of this part can be specifically referred to the scheme of generating tableVO in the foregoing embodiments.
In some implementations of the present application, the adding the indication corresponding to the annotation information to the column view object includes: if the dictionary information of the column field is acquired from the table description information of the data table, adding dictionary annotation instructions in the column view object, and adding the dictionary annotation instructions and the dictionary information into a data dictionary; the dictionary annotation indicates dictionary information for retrieving the column field from the data dictionary.
The content of this part can be specifically referred to the content of step 3.6 to step 3.11 in the foregoing embodiment.
In some implementations of the present application, the adding the indication corresponding to the annotation information to the column view object includes: if the index information of the column field is acquired from the table description information of the data table, an index annotation indication is added to the column view object; and if the index information is a primary key index, setting information of a primary key strategy member in the table view object.
The content of this part can be specifically referred to the content of step 3.17 in the foregoing embodiment.
In some implementations of the present application, the adding the indication corresponding to the annotation information to the column view object includes: if the check information of the column field is acquired from the table description information of the data table and/or the table configuration information of the data table, adding a check annotation indication in the column view object; the check annotation indicates a check class indicating the column member.
The content of this part can be specifically referred to the content of step 3.19 in the foregoing embodiment.
In some implementations of the present application, the generating code files for front and back ends of the data table according to the table view object and a preset front and back end code template includes: loading the table view object to a back-end DTO file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end DTO code file; loading the table view object to a back-end POJO file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end POJO code file; loading the table view object to a back-end Mapper file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Mapper code file; loading the table view object to a back-end Service file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Service code file; and loading the table view object to a front-end and back-end connected Controller file template contained in the front-end and back-end code templates in the table configuration information through a template engine to generate a front-end and back-end Controller code file.
In some implementations of the present application, the loading, by the template engine, the table view object to a back-end DTO file template included in a front-end code template and a back-end code template in the table configuration information to generate a back-end DTO code file includes: for each column view object, based on a back-end DTO file template, when a primary key field of the column view object is consistent with a primary key field of a table view object, generating a back-end DTO code with primary key annotation; generating a back-end DTO code with value annotation aiming at the field with value constraint; generating a back-end DTO code with dictionary annotation indication aiming at the field with the dictionary annotation indication; the loading, by the template engine, the table view object to a back-end POJO file template included in a front-end code template and a back-end code template in the table configuration information to generate a back-end POJO code file includes: generating a back-end POJO code with index information by aiming at index annotation indication in the table view object through a back-end POJO file template; loading the table view object to a back-end Mapper file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Mapper code file, wherein the generating comprises: generating a back-end Mapper code of database operation with index information by a back-end Mapper file template aiming at index annotation indication in the table view object; loading the table view object to a back-end Service file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Service code file, wherein the method comprises the following steps: generating a back-end Service code with index information and an uploading and downloading function through a back-end Service file template aiming at the index annotation indication in the table view object and the uploading and downloading function indication in the table view object; the loading, by the template engine, the table view object to a Controller file template connecting a front end and a back end, which is included in the front-back end code template in the table configuration information, and generating a front-end Controller code file, includes: and aiming at the uploading and downloading function indication in the table view object, generating a front-end and back-end Controller code with an HTTP interface through a Controller file template connected with the front end and the back end.
The content of this part can be specifically referred to the content of step 104 in the foregoing embodiment.
Based on the same concept, an embodiment of the present application provides a device for generating a front-end code file and a back-end code file for accessing a database, and as shown in fig. 4, the device for generating a front-end code file and a back-end code file for accessing a database provided by the embodiment of the present application is schematically illustrated, and the device includes a reading unit 401, an obtaining unit 402, a creating unit 403, and a generating unit 404;
a reading unit 401, configured to read a database configuration file; the database configuration file comprises database connection information and table configuration information of each data table; the table configuration information is provided with various configuration information of front and back end code files for generating the data table;
an obtaining unit 402, configured to obtain, for any one of the access data tables, table description information of the data table through the database connection information; wherein, the table description information is provided with various attribute information describing the data table;
a creating unit 403, configured to create a table view object of the data table according to the table configuration information of the data table and the table description information of the data table; the table view objects comprise column view objects, at least one column view object comprises annotation information of column fields, and the annotation information is used for setting limits on field values of the column fields in the front-end and back-end interaction process;
a generating unit 404, configured to generate code files for front and back ends of the data table according to the table view object and a preset front and back end code template.
Further, for the apparatus, the creating unit 403 is specifically configured to: creating an initial table view object; the initial table view object comprises a plurality of pending members; for any column field in a column member of the plurality of pending members, creating a column view object for the column field; if the table description information of the data table and/or the table configuration information of the data table has annotation information of the column field, adding an indication corresponding to the annotation information to the column view object, thereby generating the table view object of the data table.
Further, for the apparatus, the creating unit 403 is specifically configured to: if the dictionary information of the column field is acquired from the table description information of the data table, adding dictionary annotation instructions in the column view object, and adding the dictionary annotation instructions and the dictionary information into a data dictionary; the dictionary annotation indicates dictionary information for retrieving the column field from the data dictionary.
Further, for the apparatus, the creating unit 403 is specifically configured to: if the index information of the column field is acquired from the table description information of the data table, an index annotation indication is added to the column view object; and if the index information is a primary key index, setting information of a primary key strategy member in the table view object.
Further, for the apparatus, the creating unit 403 is specifically configured to: if the check information of the column field is acquired from the table description information of the data table and/or the table configuration information of the data table, adding a check annotation indication in the column view object; the check annotation indicates a check class used to indicate the column field.
Further, for the apparatus, the generating unit 404 is specifically configured to: loading the table view object to a back-end DTO file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end DTO code file; loading the table view object to a back-end POJO file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end POJO code file; loading the table view object to a back-end Mapper file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Mapper code file; loading the table view object to a back-end Service file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Service code file; and loading the table view object to a front-end and back-end connected Controller file template contained in the front-end and back-end code templates in the table configuration information through a template engine to generate a front-end and back-end Controller code file.
Further, for the apparatus, the generating unit 404 is specifically configured to: for each column view object, based on a back-end DTO file template, when a primary key field of the column view object is consistent with a primary key field of a table view object, generating a back-end DTO code with primary key annotation; generating a back-end DTO code with value annotation aiming at the field with value constraint; generating a back-end DTO code with dictionary annotation indication aiming at the field with the dictionary annotation indication; generating a back-end POJO code with index information by aiming at index annotation indication in the table view object through a back-end POJO file template; generating a back-end Mapper code of database operation with index information by a back-end Mapper file template aiming at index annotation indication in the table view object; generating a back-end Service code with index information and an uploading and downloading function through a back-end Service file template aiming at the index annotation indication in the table view object and the uploading and downloading function indication in the table view object; and aiming at the uploading and downloading function indication in the table view object, generating a front-end and back-end Controller code with an HTTP interface through a Controller file template connected with the front end and the back end.
The embodiment of the present application further provides a computing device, which may specifically be a desktop computer, a portable computer, a smart phone, a tablet computer, a Personal Digital Assistant (PDA), and the like. The computing device may include a Central Processing Unit (CPU), memory, input/output devices, etc., the input devices may include a keyboard, mouse, touch screen, etc., and the output devices may include a Display device, such as a Liquid Crystal Display (LCD), a Cathode Ray Tube (CRT), etc.
Memory, which may include Read Only Memory (ROM) and Random Access Memory (RAM), provides the processor with program instructions and data stored in the memory. In an embodiment of the present application, the memory may be configured to store program instructions for a method of generating a front-end code file for accessing a database;
and the processor is used for calling the program instructions stored in the memory and executing the generation method of the front-end code file and the back-end code file for accessing the database according to the obtained program.
As shown in fig. 5, a schematic diagram of a computing device provided in an embodiment of the present application includes:
a processor 501, a memory 502, a transceiver 503, a bus interface 504; the processor 501, the memory 502 and the transceiver 503 are connected through a bus 505;
the processor 501 is configured to read the program in the memory 502 and execute the method for generating the front-end and back-end code files for accessing the database;
the processor 501 may be a Central Processing Unit (CPU), a Network Processor (NP), or a combination of a CPU and an NP. But also a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a Programmable Logic Device (PLD), or a combination thereof. The PLD may be a Complex Programmable Logic Device (CPLD), a field-programmable gate array (FPGA), a General Array Logic (GAL), or any combination thereof.
The memory 502 is used to store one or more executable programs, which may store data used by the processor 501 in performing operations.
In particular, the program may include program code including computer operating instructions. Memory 502 may include volatile memory (volatile memory), such as random-access memory (RAM); the memory 502 may also include a non-volatile memory (non-volatile memory), such as a flash memory (flash memory), a Hard Disk Drive (HDD) or a solid-state drive (SSD); the memory 502 may also comprise a combination of memories of the kind described above.
The memory 502 stores elements, executable modules or data structures, or subsets thereof, or expanded sets thereof:
and (3) operating instructions: including various operational instructions for performing various operations.
Operating the system: including various system programs for implementing various basic services and for handling hardware-based tasks.
The bus 505 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 5, but this is not intended to represent only one bus or type of bus.
The bus interface 504 may be a wired communication access port, a wireless bus interface, or a combination thereof, wherein the wired bus interface may be, for example, an ethernet interface. The ethernet interface may be an optical interface, an electrical interface, or a combination thereof. The wireless bus interface may be a WLAN interface.
The embodiment of the application also provides a computer-readable storage medium, which stores computer-executable instructions for enabling a computer to execute a method for generating front-end and back-end code files for accessing a database.
It will be apparent to those skilled in the art that embodiments of the present application may be provided as a method, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A method for generating a front-end code file for accessing a database, comprising:
reading a database configuration file; the database configuration file comprises database connection information and table configuration information of each data table; the table configuration information is provided with various configuration information of front and back end code files for generating the data table;
aiming at any data table in the data tables, acquiring the table description information of the data table through the database connection information; wherein, the table description information is provided with various attribute information describing the data table;
creating a table view object of the data table according to the table configuration information of the data table and the table description information of the data table; the table view objects comprise column view objects, at least one column view object comprises annotation information of column fields, and the annotation information is used for setting limits on field values of the column fields in the front-end and back-end interaction process;
and generating code files aiming at the front end and the rear end of the data table according to the table view object and a preset front end code template and a preset rear end code template.
2. The method of claim 1,
the creating a table view object of the data table according to the table configuration information of the data table and the table description information of the data table includes:
creating an initial table view object; the initial table view object comprises a plurality of pending members;
for any column field in a column member of the plurality of pending members, creating a column view object for the column field;
if the table description information of the data table and/or the table configuration information of the data table has annotation information of the column field, adding an indication corresponding to the annotation information to the column view object, thereby generating the table view object of the data table.
3. The method of claim 2,
the adding the indication corresponding to the annotation information to the column view object includes:
if the dictionary information of the column field is acquired from the table description information of the data table, adding dictionary annotation instructions in the column view object, and adding the dictionary annotation instructions and the dictionary information into a data dictionary; the dictionary annotation indicates dictionary information for retrieving the column field from the data dictionary.
4. The method of claim 2,
the adding the indication corresponding to the annotation information to the column view object includes:
if the index information of the column field is acquired from the table description information of the data table, an index annotation indication is added to the column view object; and if the index information is a primary key index, setting information of a primary key strategy member in the table view object.
5. The method of claim 2,
the adding the indication corresponding to the annotation information to the column view object includes:
if the check information of the column field is acquired from the table description information of the data table and/or the table configuration information of the data table, adding a check annotation indication in the column view object; the check annotation indicates a check class used to indicate the column field.
6. The method of any one of claims 1 to 5,
the generating of each code file for the front end and the back end of the data table according to the table view object and a preset front end and back end code template comprises:
loading the table view object to a back-end DTO file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end DTO code file;
loading the table view object to a back-end POJO file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end POJO code file;
loading the table view object to a back-end Mapper file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Mapper code file;
loading the table view object to a back-end Service file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Service code file;
and loading the table view object to a front-end and back-end connected Controller file template contained in the front-end and back-end code templates in the table configuration information through a template engine to generate a front-end and back-end Controller code file.
7. The method of claim 6,
loading the table view object to a back-end DTO file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end DTO code file, wherein the method comprises the following steps:
for each column view object, based on a back-end DTO file template, when a primary key field of the column view object is consistent with a primary key field of a table view object, generating a back-end DTO code with primary key annotation; generating a back-end DTO code with value annotation aiming at the field with value constraint; generating a back-end DTO code with dictionary annotation indication aiming at the field with the dictionary annotation indication;
the loading, by the template engine, the table view object to a back-end POJO file template included in a front-end code template and a back-end code template in the table configuration information to generate a back-end POJO code file includes:
generating a back-end POJO code with index information by aiming at index annotation indication in the table view object through a back-end POJO file template;
loading the table view object to a back-end Mapper file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Mapper code file, wherein the generating comprises:
generating a back-end Mapper code of database operation with index information by a back-end Mapper file template aiming at index annotation indication in the table view object;
loading the table view object to a back-end Service file template contained in a front-end code template and a back-end code template in the table configuration information through a template engine to generate a back-end Service code file, wherein the method comprises the following steps:
generating a back-end Service code with index information and an uploading and downloading function through a back-end Service file template aiming at the index annotation indication in the table view object and the uploading and downloading function indication in the table view object;
the loading, by the template engine, the table view object to a Controller file template connecting a front end and a back end, which is included in the front-back end code template in the table configuration information, and generating a front-end Controller code file, includes:
and aiming at the uploading and downloading function indication in the table view object, generating a front-end and back-end Controller code with an HTTP interface through a Controller file template connected with the front end and the back end.
8. An apparatus for generating a front-end code file for accessing a database, comprising:
the reading unit is used for reading the database configuration file; the database configuration file comprises database connection information and table configuration information of each data table; the table configuration information is provided with various configuration information of front and back end code files for generating the data table;
the acquisition unit is used for acquiring the table description information of the data table through the database connection information aiming at any one data table in each access data table; wherein, the table description information is provided with various attribute information describing the data table;
the creating unit is used for creating a table view object of the data table according to the table configuration information of the data table and the table description information of the data table; the table view objects comprise column view objects, at least one column view object comprises annotation information of column fields, and the annotation information is used for setting limits on field values of the column fields in the front-end and back-end interaction process;
and the generating unit is used for generating each code file aiming at the front end and the back end of the data table according to the table view object and a preset front end code template and a preset back end code template.
9. A computer device, comprising:
a memory for storing a computer program;
a processor for calling a computer program stored in said memory, for executing the method according to any one of claims 1-7 in accordance with the obtained program.
10. A computer-readable storage medium having stored thereon computer-executable instructions for causing a computer to perform the method of any one of claims 1-7.
CN202111611427.1A 2021-12-27 2021-12-27 Method and device for generating front-end and back-end code files for accessing database Pending CN114281331A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111611427.1A CN114281331A (en) 2021-12-27 2021-12-27 Method and device for generating front-end and back-end code files for accessing database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111611427.1A CN114281331A (en) 2021-12-27 2021-12-27 Method and device for generating front-end and back-end code files for accessing database

Publications (1)

Publication Number Publication Date
CN114281331A true CN114281331A (en) 2022-04-05

Family

ID=80876201

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111611427.1A Pending CN114281331A (en) 2021-12-27 2021-12-27 Method and device for generating front-end and back-end code files for accessing database

Country Status (1)

Country Link
CN (1) CN114281331A (en)

Similar Documents

Publication Publication Date Title
US6996589B1 (en) System and method for database conversion
US7599948B2 (en) Object relational mapping layer
CN109558575B (en) Online form editing method, online form editing device, computer equipment and storage medium
US7194485B2 (en) Mapping XML schema components to qualified java components
US7703007B2 (en) Importing and exporting markup language data in a spreadsheet application document
US9811604B2 (en) Method and system for defining an extension taxonomy
US20110113074A1 (en) Data export/import from multiple data source to a destination data repository using corresponding data exporters and an importer
US7743071B2 (en) Efficient data handling representations
AU2017352446B2 (en) Rendering user-interface elements based on variation Metamodels
US7805466B2 (en) Storing and loading data in an array-based computing environment
US8615526B2 (en) Markup language based query and file generation
US20030177481A1 (en) Enterprise information unification
CN107145480B (en) Method for compiling XBRL report based on Word
US20080215621A1 (en) Metamodel-based automatic report generation
US20120166443A1 (en) Easily queriable software repositories
US9229984B2 (en) Parameter expressions for modeling user defined function execution in analytical data processing systems
US7720831B2 (en) Handling multi-dimensional data including writeback data
CN103778107A (en) Method and platform for quickly and dynamically generating form based on EXCEL
CN104881275A (en) Electronic spreadsheet generating method and device
US7877417B2 (en) Method and apparatus for exchanging data with a database
US20050038629A1 (en) Pricing of enterprise information resource management systems
CN113032393A (en) Method and device for binding associated object
Jennings Professional ADO. NET 3.5 with LINQ and the Entity Framework
TW201525737A (en) Method for automatically generating website interactive program
CN115934716A (en) Method for importing Excel table data into database based on metadata definition and implementation

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