A method and device for generating front-end and back-end code files for accessing a database
By creating table view objects and combining preset front-end and back-end code templates to generate front-end and back-end code files, the complex and unfriendly problems of existing tools when generating code, and improve development efficiency and development speed.
Patent Information
- Application Number
- CN202111611427.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2041-12-27
AI Technical Summary
Existing automatic code generation tools are complex and unfriendly when generating front-end code files, and cannot fully process field restrictions, nullity, primary keys, indexes and other information in database table information, resulting in developers needing to write a large amount of repetitive code manually, reducing development efficiency.
By reading the database configuration file and table configuration information, a table view object is created, which includes the column view object, and the column view object contains the annotation information of the column fields. Based on the table view object and preset front and back-end code templates, generate front and back-end code files for database tables, including DTO, POJO, Mapper, Service, Controller and other files.
It greatly reduces the workload of developers and shortens the development cycle of the business system. It can generate corresponding verification annotations, enumeration value verification, and index addition, deletion, modification and query operations based on the specific design of the database field, annotation information, index design, etc.
Smart Images

Figure CN114281331B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of financial technology (Fintech), and in particular, to a method and device for generating front-end and back-end code files for accessing a database. Background Art
[0002] With the development of computer technology, more and more technologies (such as cloud computing, big data or blockchain) are applied in the financial field, and the traditional financial industry is gradually transforming into financial technology. For example, for the financial department of a bank, if tax-related reports are only produced by manpower, this is obviously unable to meet the needs in the current environment with massive data. Therefore, banks generally need to develop corresponding counter systems to perform tax statistics and declarations. Among them, since tax declarations generally have the characteristics of many tax types, complex declaration forms and various data types, the number of statistical data tables and various calculation tables involved in a certain tax type is amazing. Generally speaking, a data table in the database corresponds to a front-end page. After the developer has designed the database table structure for implementing the counter system, the developer still needs to manually write the following front-end and back-end code files corresponding to each database table, including: Data Transfer Object (DTO) files corresponding to the database table, mapper files for operating the database interface, service files that provide actual business implementation for the back-end interface, controller files that provide the back-end interface, and vue files that provide front-end styles and operation pages.
[0003] Given the complex structure of database tables and the large number of tables, the method described above that relies on developers to manually write the front-end and back-end code files of the counter system is not only cumbersome but also prone to errors. For this reason, developers currently use some automatic code generation tools to generate front-end and back-end code files. The following are common ones:
[0004] mybatis-generator is an automatic code generation tool dedicated to mybatis. After providing the configuration information and table information of the corresponding database, it can automatically generate the code required for mabytis execution according to the table structure in the database, such as mapper.java, mapper.xml and DTO files.
[0005] mybatis-plus generator is an automatic code generation tool for the upgraded version of mybatis. Based on mybatis-generator, it can also generate controller and service interfaces, serviceImpl files, and specify the package path of each file.
[0006] For automatic generation of front-end code, vscode provides plug-ins that can generate blank vue templates, and there are also some drag-and-drop page generation tools on the market.
[0007] However, the above solution of generating front-end and back-end code files based on automatic code generation tools has the following disadvantages:
[0008] 1. In order to meet the requirements of versatility, the current automatic code generation tools are relatively complicated to use. For example, mybatis-generator needs to be configured using XML files, and needs to specify the path and class name for the files corresponding to each database table, and can only generate partial framework code. In addition, when using the drag-and-drop automatic code generation tool applied to the front end, developers need to manually enter the required fields, which is obviously very unfriendly to various wide tables of the tax system.
[0009] 2. The current automatic code generation tools can only generate basic codes based on the field names and field types of the table, but have not fully processed the field restrictions, nullability, primary keys, indexes and other information provided in the table information. Some data verification and common file operations in the counter system still require developers to write code manually. A large amount of repetitive work reduces development efficiency.
[0010] Therefore, there is an urgent need for an efficient method for automatically generating front-end and back-end code files for counter systems. Summary of the invention
[0011] The present application provides a method and device for generating front-end and back-end code files for accessing a database, so as to efficiently and automatically generate front-end and back-end code files for a counter system.
[0012] In a first aspect, an embodiment of the present application provides a method for generating front-end and back-end code files for accessing a database, the method comprising: reading a database configuration file; the database configuration file comprising database connection information and table configuration information of each data table; wherein the table configuration information is provided with various configuration information for generating front-end and back-end code files of the data table; for any data table in the data tables, obtaining 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; according to the table configuration information of the data table and the table description information of the data table, creating a table view object of the data table; the table view object comprises various column view objects, at least one column view object comprises annotation information of the column field, and the annotation information is used to set restrictions on the field value of the column field during the front-end and back-end interaction process; according to the table view object and preset front-end and back-end code templates, generating various code files for the data table at the front-end and back-end.
[0013] In the above scheme, for a business system, after the developer completes the basic database table design, that is, designs the corresponding table description information for any database table, all the basic codes required for the project can be generated through simple configuration (including database configuration files and table configuration information), which not only covers the code of general database operations, but also can generate corresponding verification annotations, enumeration value verification, index addition, deletion, modification and query operation codes according to the specific design, annotation information and index design of the database field. This greatly reduces the workload of developers and shortens the development cycle of the business system.
[0014] In a possible implementation method, the table view object of the data table is created according to the table configuration information of the data table and the table description information of the data table, including: creating an initial table view object; the initial table view object includes multiple pending members; for any column field in the column members of the multiple pending members, creating a column view object of 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.
[0015] In the above scheme, by creating a table view object, all the information of each data table used to build the business system can be obtained; in particular, by creating a column view object for any column field in the column member of the table view object, after obtaining the annotation information of the column field, the obtained annotation information can be added to the corresponding column view object. In this way, when generating the front-end and back-end code files, the corresponding annotations can be automatically injected into the fields that need to be specially set, for example, to meet the needs of setting field nullability, field verification, and field value enumeration.
[0016] In one possible implementation method, adding an indication corresponding to the annotation information to the column view object includes: if the dictionary information of the column field is obtained from the table description information of the data table, adding a dictionary annotation indication to the column view object, and adding the dictionary annotation indication and the dictionary information to the data dictionary; the dictionary annotation indication is used to obtain the dictionary information of the column field from the data dictionary.
[0017] 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 will only be converted to corresponding description information for display on the front end. For such fields, this scheme presets the field annotations of the table description information of the database table in the format of {enumeration value 1-meaning, enumeration value 2-meaning, enumeration value 3-meaning}, so that when traversing the annotation information in the field information, if a string in the above format is found, it means that it is necessary to add annotations to the field in the column view object corresponding to the field, that is, to add dictionary annotation instructions, and then when using the field, it can be converted to the enumeration value stored in the database based on the description information entered by the user, and the enumeration value stored in the database can be converted into description information that the user can understand after querying.
[0018] In one possible implementation method, adding the indication corresponding to the annotation information to the column view object includes: if the index information of the column field is obtained from the table description information of the data table, adding the index annotation indication in the column view object; wherein, if the index information is a primary key index, setting the information of the primary key strategy member in the table view object.
[0019] In the above scheme, for any data table in the database, multiple fields can be used to display the information that the data table needs to transmit to the outside, and these fields will need to meet relevant requirements when filling in corresponding values. The requirements set for each field can be expressed as the improvement of the information of each column view object in the table view object. For any field, in addition to reading the table description information of the field in the data table, the annotations obtained in advance for configuring the field are written in the column view object corresponding to the field, specifically in the annotation list of the column view object, and it also includes determining whether the annotations of the fields with the same name can be further improved from the perspective of the index information in the table description information, so that the field annotations in the column view object corresponding to each field will be the most complete. When the data table generated based on the table view object is applied in the front-end and back-end code files, it will be possible to achieve the expected functions of each field in the data table by the business system developers when designing the data table.
[0020] In one possible implementation method, adding an indication corresponding to the annotation information to the column view object includes: if the verification information of the column field is obtained from the table description information of the data table and / or the table configuration information of the data table, adding a verification annotation indication to the column view object; the verification annotation indication is used to indicate the verification class of the column field.
[0021] In the above scheme, for any data table in the database, multiple fields can be used to display the information that the data table needs to transmit to the outside, and when these fields are filled with corresponding values, they will need to meet relevant requirements, such as whether they are empty, whether they support upload, download, and calculation functions, or other field verification rules customized by developers. Therefore, when the information of each column view object in the table view object is improved, for any field, in addition to reading the table description information of the field in the data table, and writing the obtained annotations for the required configuration of the field in advance in the column view object corresponding to the field, specifically, in the annotation list of the column view object, it also includes determining whether the annotations of the fields with the same name can be further improved from the perspective of the table configuration information of the data table, so that the field annotations in the column view object corresponding to each field will be the most complete, and the data table generated based on the table view object in the subsequent front-end and back-end code files will be applied, so that each field in the data table can achieve the expected functions of the business system developers when designing the data table.
[0022] In a possible implementation method, the code files for the front-end and back-end of the data table are generated according to the table view object and the preset front-end and back-end code templates, including: loading the table view object into the back-end DTO file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a back-end DTO code file; loading the table view object into the back-end POJO file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a back-end POJO code file; loading the table view object into the back-end Mapper file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a back-end Mapper code file; loading the table view object into the back-end Service file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a back-end Service code file; loading the table view object into the Controller file template for connecting the front-end and back-end included 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.
[0023] In the above solution, for a data table in the database, since the key information that needs to be filled in the code file can be encapsulated through the table view object, and some dependent related classes have been provided in the JAR, the template engine can be used to pass the basic data model required for each file into the interface of the template engine to generate the code files of the data table at the front and back ends.
[0024] In a possible implementation method, the table view object is loaded into the backend DTO file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a backend DTO code file, including: for each column view object, based on the backend DTO file template, when the primary key field of the column view object is consistent with the primary key field of the table view object, a backend DTO code with a primary key annotation is generated; for a field with a value constraint, a backend DTO code with a value annotation is generated; for a field with a dictionary annotation indication, a backend DTO code with a dictionary annotation indication is generated; the table view object is loaded into the backend POJO file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a backend POJO code file, including: for an index annotation indication in the table view object, a backend POJO code with index information is generated through the backend POJO file template; the table view object is loaded into the backend Mapper file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate The back-end Mapper code file includes: for the index annotation indication in the table view object, through the back-end Mapper file template, generating the back-end Mapper code for database operations with index information; the table view object is loaded into the back-end Service file template included in the front-end and back-end code templates in the table configuration information through the template engine to generate the back-end Service code file, including: for the index annotation indication in the table view object and the upload and download function indication in the table view object, through the back-end Service file template, generating the back-end Service code with index information and upload and download functions; the table view object is loaded into the Controller file template for connecting the front-end and back-end included in the front-end and back-end code templates in the table configuration information through the template engine to generate the front-end Controller code file, including: for the upload and download function indication in the table view object, through the Controller file template connecting the front-end and back-end, generating the front-end Controller code with HTTP interface.
[0025] In the above scheme, a method for generating various code files for a data table at the front-end and back-end is specifically described. Ultimately, by running the various code files of the data table at the front-end and back-end, the automatic generation of the data table at the front-end and back-end can be achieved. The automatically generated data table can meet the general restrictions made by business system developers on the data and the personalized restrictions made on certain fields in the data table.
[0026] In a second aspect, an embodiment of the present application provides a device for generating front-end and back-end code files for accessing a database, the device comprising: a reading unit, for reading a database configuration file; the database configuration file comprises database connection information and table configuration information of each data table; wherein the table configuration information is provided with various configuration information for generating front-end and back-end code files of the data table; an acquisition unit, for acquiring, for any data table in the accessed data tables, 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; a creation unit, 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 object comprises various column view objects, at least one column view object comprises annotation information of the column field, and the annotation information is used to set restrictions on the field value of the column field during the front-end and back-end interaction process; a generation unit, for generating various code files for the data table at the front-end and back-end according to the table view object and preset front-end and back-end code templates.
[0027] In a third aspect, an embodiment of the present application provides a computing device, including:
[0028] A memory for storing program instructions;
[0029] The processor is used to call the program instructions stored in the memory and execute any implementation method of the first aspect according to the obtained program.
[0030] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute any implementation method of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0032] Figure 1 A schematic diagram of a process for automatically generating front-end and back-end code files provided in an embodiment of the present application;
[0033] Figure 2 A schematic diagram of a process of constructing a table view object provided in an embodiment of the present application;
[0034] Figure 3 A schematic diagram of a method for generating front-end and back-end code files for accessing a database provided in an embodiment of the present application;
[0035] Figure 4 A schematic diagram of a device for generating front-end and back-end code files for accessing a database provided in an embodiment of the present application;
[0036] Figure 5 A schematic diagram of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0038] Take the financial department of a bank as an example. In the process of producing tax-related report data stipulated by the state, it can build a counter system to produce various declaration forms, thereby greatly reducing the burden on relevant financial personnel who originally needed to manually produce declaration forms. However, for the current solution of generating a counter system by running the front-end and back-end codes corresponding to the counter system generated by the automated code generation tool, it is still unable to make the corresponding user-desired settings for some fields in the data table that need to be specially defined, resulting in the generated counter system having relatively simple functions. In other words, for the counter system generated by running the front-end and back-end codes generated by the automated code generation tool, the counter system cannot currently be well integrated with business scenario requirements.
[0039] In view of the above technical problems, the present application provides the following solutions. Based on the solutions, the above technical problems can be overcome.
[0040] For example, taking the financial department of a bank as an example, tax declaration is one of the work contents of relevant financial personnel. For example, by using the designed counter system, financial personnel can achieve the purpose of calculating various declaration forms required by the tax bureau. Among them, the calculation of the declaration form is obtained by performing a series of complex operations on the basic detailed data collected within a certain period; at the same time, in order to meet the needs of reconciliation and relevant tax law requirements, it is also necessary to save a set of intermediate tables for the data of each module of the declaration form, which is used to record the intermediate result data of the calculation process. Therefore, from the perspective of data evolution, the various data tables in the database can be classified, including collection data tables, intermediate result tables, and effective result tables.
[0041] Since there are many types of data tables stored in the database used to implement the counter system, from a business perspective, the bank hopes that the counter system can implement at least the following functions:
[0042] 1. Inspection tips for input information: such as required items, field format requirements, data range requirements, etc.;
[0043] 2. Maintenance of input information: support single entry, modification, deletion, and batch entry in file form;
[0044] 3. Multi-channel display of business information: page display, attachment export, email notification, etc., as well as multi-condition query;
[0045] 4. Generation, adjustment and recalculation of business results data.
[0046] Since the realization of business functions by the counter system is actually the process of converting business operations into changes to database tables, the above functions that the counter system is expected to realize can be mapped to the following general operations on the data table:
[0047] 1. DTO data field verification when writing data, including non-empty verification, enumeration value verification, value range verification, string length verification, and business custom verification;
[0048] 2. Conditional query, Excel upload and export of table data;
[0049] 3. Conditional query, addition and modification of single data;
[0050] 4. Recalculate table data according to account period;
[0051] 5. Conversion of data encoding and display text.
[0052] In the embodiment of the present application, taking the counter system as an example, the business system is developed based on the Java language, and the following constraints are imposed on the counter system to be developed:
[0053] 1. The names of libraries, tables, fields, and indexes should all be in the same combination of lowercase letters, numbers, and underscores. Numbers are not allowed to be the first character, and numbers are not allowed to appear between two underscores.
[0054] 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;
[0055] 3. Float and double are prohibited for numeric types. Tinyint unsigned is used for numeric enumeration values, and decimal is used for other types.
[0056] 4. Database tables and field details must be annotated;
[0057] 5. The table must have three fields: id, created_by, created_date, last_modified_by, and last_modified_date. id must be the primary key, and supports auto-increment primary keys of bigint unsigned type and custom primary keys of varchar type. The types of created_date and last_modified_date are both TIMESTAMP(3). created_by and last_modified_by are the system login users;
[0058] 6. For enumeration value fields, the comment format is "field comment, {enumeration value 1-meaning, enumeration value 2-meaning, enumeration value 3-meaning}";
[0059] 7. If there is a business primary key, set it as the table unique key;
[0060] 8. The business meaning and data entry format of fields with the same name must be consistent, and the same business field should have the same field name in different tables.
[0061] Based on the above constraints on the counter system to be generated, the present application provides a method for generating front-end and back-end code files based on the mybatis framework, springboot framework and vue framework. This method configures some files in advance and designs various template files. It can generate front-end and back-end code files corresponding to the database table, which can perform addition, deletion, modification, upload and download, field verification, display conversion and page display.
[0062] For any data table that constitutes the counter system, such as Figure 1 As shown, it is a schematic diagram of a process for automatically generating front-end and back-end code files provided in an embodiment of the present application, including the following steps:
[0063] Step 101: Read the database configuration file.
[0064] In this step, the database configuration file can be recorded as database.properties, which is used to configure the database connection information and the information of the database table to be generated. The configuration items of database.properties are shown in Table 1 below:
[0065] Fields illustrate diver_name Database Type url Database JDBC connection string username username password password tables Table name
[0066] Table 1 Configuration items of database.properties
[0067] Where diver_name indicates the type of database, url indicates the data source of the counter system to be constructed, that is, the address information of the database to be used, username and password indicate the identity authentication information when using the database, and tables indicates the table information of the relevant data tables in the database to be used by the counter system. Among them, the embodiment of the present application can provide the following two ways to configure tables:
[0068] Method 1: Only provide the table name, where the table name is separated by the specified separator. The table configuration information of each data table is based on the public parameter configuration file (config.properties). For example:
[0069] tables=table_a,table_b,table_c
[0070] Method 2: By configuring a json string, you can specify parameters for a single data table to overwrite the same-name parameter configuration in config.properties. For example:
[0071] tables={table=table_a,db_table_id=org_id,webroot_package=.. / src / },{table=table_b,db_table_id=org_id}}
[0072] Among them, the configuration items of config.properties are as follows:
[0073]
[0074]
[0075] Table 2 Configuration items of config.properties
[0076] For the configuration item db_filed_annotations in config.properties: This configuration item is used to configure the mapping relationship between fields and annotations. According to the constraints of fields with the same name in the business system, specified annotations can be added according to the field name for verification, data identity processing, etc. The configuration method can be a json string. One field can be configured with multiple annotations. The order of generating annotations is based on the configuration order. The annotation class supports annotations in hibernate-validator, javax.validation, springboot, and annotations under the annotation package of this application. If annotations are required under other paths, they can be implemented by writing the full path of the class. For example, in the counter system, time periods are often used as the concept of account periods, and the commonly used ones are monthly account periods and quarterly account periods. The corresponding monthPeriod and quaterPeriod fields must meet certain formats and be actual months or quarters. For example, the value under the monthPeriod field must be an expression of the month, not an expression of the year, and the expressed month must be between the 12 values from January to December, and cannot be a value other than the 12 values 1-12. Therefore, for the monthPeriod field, on the one hand, it is necessary to set custom restrictions on its month expression, and on the other hand, it needs to be set to be a value that can be enumerated for each month. The db_filed_annotations shown below can reflect the relationship between the monthPeriod field and the custom validation annotation:
[0077] db_filed_annotations={filed=month_period,annotations=MonthValidate,Enum Validate}
[0078] Step 102: Read the information of the database table fields in the database configuration file and generate a database table list.
[0079] That is, by reading the values corresponding to the tables fields shown in Table 1, a database table list can be generated.
[0080] Through this step, the data tables needed for the counter system can be sorted, and the initial table view object corresponding to each data table can be created in sequence. The table view object of the data table can be obtained by improving the initial table view object of each data table. In this way, when the front-end and back-end code files corresponding to each data table that needs to be used are generated later, the problems of repeated operations and missed operations on each data table during the operation process can be avoided.
[0081] Step 103: For any data table in the database table list, create an initial table view object corresponding to the data table based on the table name of the data table, and obtain the table configuration information and table description information of the data table through the database configuration file, so as to improve the initial table view object and obtain the table view object of the data table.
[0082] like Figure 2 FIG. 1 is a schematic diagram of a process for constructing a table view object provided in an embodiment of the present application, wherein: Figure 2 The construction process of the table view object shown in the figure is the sub-steps of step 103, that is, step 103 may specifically include Figure 2 The steps shown are as follows:
[0083] Step 3.1, use JDBC connection (Java Database Connectivity) to query whether the data table exists; if it is determined to exist, execute step 3.2; otherwise, re-read a data table from the database table list and execute this step for the new data table.
[0084] Step 3.2, create the initial table view object, that is, create a tableVO instance, and write the bussi_package, webroot_package, Templatepath, db_table_id, isUpload, isExport and isComputable information in the table configuration information of the data table into the corresponding pending members in tableVO.
[0085] In order to convert the table description information and table configuration information of the data table in the database into recognizable object information, this application designs the following tableVO object:
[0086]
[0087]
[0088] Among them, the columnVO object in tableVO, that is, the column view object, can be used to store field information for subsequent entity and POJO file generation:
[0089]
[0090] Among them, the indexVO object in tableVO, that is, the index view object, can be used to store multiple index information of the data table:
[0091]
[0092]
[0093] Step 3.3, use JDBC connection to query the table description information of the data table in information_schema.tables, and write the table name and table description into the corresponding members of tableVO.
[0094] Step 3.4, use JDBC connection to query the field information of the data table in information_schema.columns.
[0095] Step 3.5, traverse the field information, generate a corresponding columnVO object for each field, and hang it under the column list of tableVO.
[0096] In addition, in this step, when generating a columnVO object based on field information, the database type and Java type can be converted according to the following mapping:
[0097] Database Type Java Types 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
[0098] Step 3.6, determine whether columnVO.fieldComment contains a string in the format of {enumeration value 1-meaning 1, enumeration value 2-meaning 2, enumeration value 3-meaning 3}. If it is determined to be contained, execute step 3.7, otherwise execute step 3.12.
[0099] Among them, many complex Chinese descriptions used by the business system will be stored in the database in a fixed coding form, and will only be converted to the corresponding description information on the front end. For example, for the gender field, the user can edit "male / female" when entering on the front end, and when the back end stores the field value entered by the user in the database, it can use the corresponding coding form to store it, rather than the actual value entered by the user. For example, the number "0" is used to represent the gender of male, and the number "1" is used to represent the gender of female. In this way, when storing the value of the gender field, it can be stored as "0 / 1". In this solution, this type of field is required to be noted in the column annotation of the database table in the format of {enumeration value 1-meaning, enumeration value 2-meaning, enumeration value 3-meaning}.
[0100] For the data conversion scenario described above, the embodiment of the present application provides a data dictionary design, wherein: two tables are designed in the database, namely a data dictionary table and a data dictionary detail table, for storing the mapping relationship of each data dictionary. The data dictionary table is shown in Table 3, and the data dictionary detail table is shown in Table 4.
[0101] Fields illustrate dict_name Dictionary Name dict_code Dictionary encoding
[0102] Table 3 Data dictionary table
[0103] Fields illustrate dict_code Dictionary encoding item_value Dictionary item value item_text Dictionary item text
[0104] Table 4 Data dictionary details
[0105] The annotation class @Dict is designed. It acts on fields and marks the fields that need to be converted to data dictionary. The following annotation parameters are provided to specify the data dictionary code and dictionary item text.
[0106] String dicCode();
[0107] String dicText() default "";
[0108] On the server backend, define the AOP pointcut on the interface that needs to convert the return value into a data dictionary (usually the interface on the controller), using
[0109] @Around("dictPointCut()")
[0110] public Object around(ProceedingJoinPoint pjp)
[0111] Internal implementation of the intercept interface. pjp.proceed() obtains the original return value of the interface, and obtains the object T by parsing the returned object. Capture all member variables of T, obtain the dictCode in the annotation for members containing the @Dict annotation, query the mapping relationship of {item_value, item_text} from the database, convert the item_value stored in the member to item_text, and append it to the member of T. In addition, when the front end frequently queries a large amount of data, if the dictionary information is checked from the database each time, the query time will increase significantly. For this reason, in the embodiment of the present application, the dictionary information can be stored in the JVM memory, and the dictionary information in the JVM only needs to be actively refreshed when the database dictionary information changes.
[0112] On the server front end, in order to convert the text input or selected by the user into a value, an embodiment of the present application provides a dictionary-specific control JDictSelectTag, which encapsulates the native select control of Vue, and adds the prop option dictCode to specify the data dictionary. In this way, the item_text value is displayed to the user in the select-option, and the value sent to the server back end after the user's operation is item_value.
[0113] Step 3.7, add the data dictionary @Dict annotation in the annotations of columnVO.
[0114] In this step, by writing the @Dict annotation into the annotation list annotations corresponding to the field columnVO, the subsequent step 104 can add the annotation @Dict(dictCode="DICT_${po.fieldName}") and the enumeration value verification annotation @EnumValid(target=${po.fieldName}Enum.class) to the field ${po.fieldName} when generating the entity file corresponding to the data table; and, when generating the Vue file corresponding to the data table, the internal control of the form item corresponding to ${po.fieldName} will use JDictSelectTag instead of the Select control to automatically provide a drop-down selection for the dictionary item.
[0115] Step 3.8, generate data dictionary items dict_name and dict_code with the same name according to the columnVO field name and field comment, and concatenate the data dictionary items into the insert statement of the data dictionary table.
[0116] Step 3.9, map {enumeration value 1-meaning 1, enumeration value 2-meaning 2, enumeration value 3-meaning 3} into 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 splice the data dictionary details into the insert statement of the data dictionary details table.
[0117] Steps 3.8 and 3.9 are a method of implementing the data dictionary proposed in the embodiment of the present application: that is, if in step 3.6, if it is detected that columnVO.fieldComment contains a string in the format of {enumeration value 1-meaning 1, enumeration value 2-meaning 2, enumeration value 3-meaning 3}, then it is determined that the field needs to provide a data dictionary function. Assuming that the field name is ${fieldName}, the dml statements spliced for the field in steps 3.8 and 3.9 are as follows:
[0118] insert into sys_dict
[0119] (dict_code,dict_name)values('DICT_${fieldName}','filedComment');
[0120] insert into sys_dict_item(dict_code,item_value,item_text)values
[0121] ('DICT_${fieldName}','Meaning 1','Enumeration value 1'),
[0122] ('DICT_${fieldName}','Meaning 2','Enumeration value 2');
[0123] Step 3.10, write insert to the dml.sql file in the project path.
[0124] Step 3.11, read the enumeration class template file, pass in fieldName and enumeration value list, generate the enum class file, and save it in the . / com / weebank / enum / path of the project.
[0125] In this step, read the following enumeration class template file from the system specified path, and pass the sys_dict_item list and fileName initialized according to the annotation as parameters to the template file to generate the ${fieldName}Enum.java file.
[0126]
[0127] Step 3.12, determine whether tableVO.isUpload or isExport is true. If it is true, go to step 3.13, otherwise go to step 3.5.
[0128] Step 3.13, add @Excel annotation in the annotations of columnVO.
[0129] Step 3.14, determine whether the nullable of columnVO is true. If it is true, execute step 3.15, otherwise execute step 3.5.
[0130] Step 3.15, according to fieldType, add notNull annotation to annotations of columnVO.
[0131] Step 3.16, after completing the traversal of the field information, use the JDBC connection to query the index information of the data table in Information_schema.statistics.
[0132] Step 3.17, traverse the index information, generate a corresponding indexVO object, that is, index view object, for each index's index_name and index_comment, and hang it under the index list of tableVO.
[0133] In this step, when traversing the index, if the index type is a PRIMARY primary key index, set the primaryKeyField of tableVO to the field of the index. If the primary key field type is int or bigint and the field extra information is auto_increment, set the primary key policy of tableVO to IdType.AUTO, otherwise to IdType.INPUT. When generating the entity file in the subsequent step 104, add the TableID annotation to the member corresponding to the primary key field according to primaryKeyField and primaryKeyPolicy, and set the tableID annotation policy.
[0134] Step 3.18, read all colunmn_name of the index, search for columns with the same name in the tableVO.colunmns list, and hang them under the indexVO.column list.
[0135] Step 3.19, determine whether da_field_annotations is configured in the database.properties of the field. If it is configured, execute step 3.20, otherwise re-traverse the index information and execute step 3.17.
[0136] In the counter system, the data exchanged between the front and back ends is transmitted in the format of a defined entity object. Data verification and conversion can be achieved by adding member annotations to the entity object. Data conversion can be achieved through the data dictionary solution described above, adding the @Dict annotation to the corresponding field. Data verification can also be achieved through member annotations:
[0137] 1. After the controller layer grabs the entity object, it parses each member object in the object to see if there is a verification annotation.
[0138] 2. Find the verification implementation class specified by the verification annotation.
[0139] 3. Pass the member value to the verification implementation class, call the verification method, and return the verification result.
[0140] The entity object corresponds to a database table. If the members of the object have constraints such as non-empty and non-null, the corresponding constraints will also be set in the database table structure corresponding to the object. The Java validation package provides common validation annotations such as notblank and notnull for this purpose. In addition to the validation information that can be extracted from the database table structure, this solution provides custom data validation. According to the business meaning of a certain data column, corresponding special annotations can be set. For example, in the reporting system, the time period is often used as the concept of account period. Commonly used ones are monthly account period and quarterly account period. The corresponding monthPeriod and quaterPeriod fields must meet certain formats and be actual months or quarters. At this time, you can define @MonthPeriod and @QuarterPeriod custom validation interfaces.
[0141] For the implementation of the custom validation interface, if it is detected in step 3.14 that a field of the data table has a non-null constraint in the database, the columnVO object will be automatically injected with annotations such as notBlank; if it is detected in step 3.19 that the data table has a corresponding db_field-annotation configuration in the database configuration file, the corresponding annotation will be automatically added to the columnVO objects under the tableVO; and if it is detected in step 3.13 that the data table has upload and download function attributes, the @Excel annotation will be added to all columnVOs under the tableVO.
[0142] Step 3.20, parse the field configuration field=x, annotations=x,x,x from the configuration.
[0143] Step 3.21, according to field, find the corresponding columnVO from tableVO.column, convert annotations = x, x, x into a list, and load the class according to the class name x <x>Object, written to columnVO.annotations list.
[0144] Step 104, based on the table view object and the preset front-end and back-end code templates, generate the front-end and back-end code files of the data table. Specifically, it may include:
[0145] (1) Generate DTO (entity) file.
[0146] Before this step, all annotations defined in columnVO will be added before the corresponding members of columnVO to realize automatic injection of field annotations.
[0147] In this step, the freemarker template engine can be used for the automatic generation of code files in the embodiment of the present application. The Template.process(Object dataModel,Writer out) interface can write the data in the dataModel into the template text for output. The related classes that the automatically generated code file depends on are already provided in the dependent jar package, and the key information that needs to be filled in the code file has been basically packaged in the aforementioned steps. The freemarker template supports simple if-else and list instructions, and simple template files can be written to implement logical judgment and traversal logic. The template file can be generated by simply passing the basic data model required for each file into the interface. The basic design of the template file is as follows: according to the content of tableVO, the package path, class name, dependent class and basic code block of each code file are set.
[0148] The DTO file can automatically generate member variables that correspond to database columns one by one and add field annotations based on column annotations. It specifies the table name, package name, and table annotations. It uniformly uses lombok's @data annotation to replace traditional getter and setter methods, and supports serialization interfaces by default. In addition, validation annotations are automatically added based on database column design. The basic DTO template is as follows:
[0149]
[0150] When generating entity files in this step, the template is generated according to the following logic:
[0151] 1. Traverse the columnVO list of tableVO;
[0152] 2. For each columnVO:
[0153] 2.1. Add the member definition statement according to the field name and field type.
[0154] 2.2. If the primary key field of columnVO is consistent with that of tableVO, add @TableId annotation before the member definition statement, and the type is determined according to the primary key strategy.
[0155] 2.3. If the type of columnVO is decimal or int, read the comment filedComment. For fields with value range constraints, you can annotate them in the comment in the format of max:100,min:-1.0. Extract maxValue and minValue from the comment. And add @DecimalMin and @DecimalMax annotations.
[0156] 2.4. If the type of columnVO is String, add the string length check @ByteSizeValidator annotation according to charmaxLength.
[0157] 2.5. If the annotations list of columnVO is not empty, add the annotations in the list one by one before the columnVO definition statement.
[0158] (2) Generate POJO files
[0159] The primary key id column is generally only used to provide a unique mark for the data column and has no business meaning itself. In the actual database table design, there will also be an actual primary key column with business meaning. Due to the introduction of the concept of account period, it is usually a combination of multiple columns and set as a unique index to ensure data correctness while improving query performance. This actual business primary key is used frequently in business operations and appears in the input parameters and return values of many business methods. In order to improve database operation efficiency, some commonly used field combinations are also set as ordinary indexes. To this end, this solution provides automatic generation of combined index POJO. It reduces the complexity of method signatures, eliminates some duplicate codes, and improves code readability:
[0160] In this step, we get the index information indexs from tableVO, ignore the primary key information, traverse the remaining indexes, and generate a POJO file for each index. The index POJO file template is as follows:
[0161]
[0162]
[0163] (3) Generate Mapper file.
[0164] The Mapper file inherits com.baomidou.mybatisplus.core.mapper.BaseMapper <t>Generic interface, automatically realizes the addition of table data, deletion and modification by primary key, and can also use Wrapper <t>Customize SQL conditions. The Mapper basic template is as follows:
[0165]
[0166] In this step, when the template generates a file, if the tableVO contains an index, the following data query, modification, and deletion methods for the index are added to the generated file according to the index name:
[0167]
[0168]
[0169] (4) Generate Service file.
[0170] The Service method inherits the com.baomidou.mybatisplus.extension.service.impl.ServiceImpl generic class, and automatically inherits the basic operations of adding, deleting, modifying and checking the generic type T implemented by this class. The basic template of Service is as follows:
[0171]
[0172] In this step, when generating the Service file, if the tableVO contains an index, add the following method to the generated file according to the index name:
[0173]
[0174]
[0175] If the isUpload property of tableVO is true, add an upload method for the Service file:
[0176] int importExcel(File file,String username)
[0177] If the isExport property of tableVO is true, add a download method for the Service file:
[0178] workbook exportExcel(HttpRequest request,${entityName}object)
[0179] (5) Generate Controller file.
[0180] The Controller method inherits the BaseController designed in this solution <t>Generic class, encapsulating the logic implementation of common interfaces such as page query, add, modify, delete, batch operation, etc. The actual controller class generated for a single table will automatically replace the input parameters and return objects of the corresponding interface according to the DTO class. The Controller class itself is only used to specify the URL and expose the interface, and there is no need to implement the specific logic of each backend interface by yourself. The basic Controller template is as follows:
[0181]
[0182]
[0183] In this step, similar to the logic of the Service file, if the tableVO sets the isUpload or isExport attribute, the corresponding HTTP interface code block is added to the generated file.
[0184] (6) Generate Vue files.
[0185] A single table corresponds to a Vue file. The general page design provides a query form box, an operation button area, and a table data display area. It supports querying specified values of any column.
[0186] Among them, for the front-end and back-end code files to be generated in step 104, their generation order can be customized and is not limited to the generation order provided in this application.
[0187] Put the dml file generated by the above process in the database for execution, and put the counter system code generated by the above template in the project path, and you can create a multi-table basic counter system that supports the addition, deletion, modification and query of a single data, batch operation of data, and arbitrary condition query of table data.
[0188] Therefore, based on the process of generating the front-end and back-end code files of a data table described in detail above, the embodiment of the present application provides a method for generating the front-end and back-end code files for accessing a database, such as Figure 3 As shown, it is a schematic diagram of a method for generating front-end and back-end code files for accessing a database provided by an embodiment of the present application. The method can be executed by a device for generating front-end and back-end code files for accessing a database, such as a server. The method includes the following steps:
[0189] Step 301, read a database configuration file; the database configuration file includes database connection information and table configuration information of each data table; wherein the table configuration information is provided with various configuration information of the front-end and back-end code files for generating the data table;
[0190] Step 302: for any data table in the data tables, obtain 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;
[0191] 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 object includes column view objects, at least one column view object includes annotation information of a column field, and the annotation information is used to set restrictions on the field value of the column field during the front-end and back-end interaction process;
[0192] Step 304: Generate front-end and back-end code files for the data table according to the table view object and preset front-end and back-end code templates.
[0193] In the above scheme, for a business system, after the developer completes the basic database table design, that is, designs the corresponding table description information for any database table, all the basic codes required for the project can be generated through simple configuration (including database configuration files and table configuration information), which not only covers the code of general database operations, but also can generate corresponding verification annotations, enumeration value verification, index addition, deletion, modification and query operation codes according to the specific design, annotation information and index design of the database field. This greatly reduces the workload of developers and shortens the development cycle of the business system.
[0194] The following will explain the above steps in detail with examples.
[0195] In an implementation of the above step 303, the table view object of the data table is created according to the table configuration information of the data table and the table description information of the data table, including: creating an initial table view object; the initial table view object includes multiple pending members; for any column field in the column members of the multiple pending members, creating a column view object of 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, then adding an indication corresponding to the annotation information to the column view object, thereby generating the table view object of the data table.
[0196] For details of this part, please refer to the solution for generating tableVO in the aforementioned embodiment.
[0197] In certain implementations of the present application, adding an indication corresponding to the annotation information to the column view object includes: if the dictionary information of the column field is obtained from the table description information of the data table, adding a dictionary annotation indication to the column view object, and adding the dictionary annotation indication and the dictionary information to the data dictionary; the dictionary annotation indication is used to obtain the dictionary information of the column field from the data dictionary.
[0198] For details of this part, please refer to the contents of steps 3.6 to 3.11 in the above-mentioned embodiment.
[0199] In certain implementations of the present application, adding an indication corresponding to the annotation information to the column view object includes: if the index information of the column field is obtained from the table description information of the data table, adding an index annotation indication to the column view object; wherein, if the index information is a primary key index, setting the information of the primary key strategy member in the table view object.
[0200] For details of this part, please refer to the content of step 3.17 in the above embodiment.
[0201] In certain implementations of the present application, adding an indication corresponding to the annotation information to the column view object includes: if the verification information of the column field is obtained from the table description information of the data table and / or the table configuration information of the data table, adding a verification annotation indication to the column view object; the verification annotation indication is used to indicate the verification class of the column member.
[0202] For details of this part, please refer to the content of step 3.19 in the above embodiment.
[0203] In certain implementations of the present application, the code files for the data table at the front-end and back-end are generated according to the table view object and the preset front-end and back-end code templates, including: loading the table view object into the back-end DTO file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a back-end DTO code file; loading the table view object into the back-end POJO file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a back-end POJO code file; loading the table view object into the back-end Mapper file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a back-end Mapper code file; loading the table view object into the back-end Service file template included in the front-end and back-end code templates in the table configuration information through a template engine to generate a back-end Service code file; loading the table view object into the Controller file template for connecting the front-end and back-end included 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.
[0204] In certain implementations of the present application, the table view object is loaded into the backend DTO file template included in the front-end and back-end code templates in the table configuration information through the template engine to generate a backend DTO code file, including: for each column view object, based on the backend DTO file template, when the primary key field of the column view object is consistent with the primary key field of the table view object, a backend DTO code with a primary key annotation is generated; for fields with value constraints, a backend DTO code with a value annotation is generated; for fields with dictionary annotation indications, a backend DTO code with a dictionary annotation indication is generated; the table view object is loaded into the backend POJO file template included in the front-end and back-end code templates in the table configuration information through the template engine to generate a backend POJO code file, including: for the index annotation indication in the table view object, a backend POJO code with index information is generated through the backend POJO file template; the table view object is loaded into the backend Mapper file template included in the front-end and back-end code templates in the table configuration information through the template engine to generate The back-end Mapper code file includes: for the index annotation indication in the table view object, through the back-end Mapper file template, generating the back-end Mapper code for database operations with index information; the table view object is loaded into the back-end Service file template included in the front-end and back-end code templates in the table configuration information through the template engine to generate the back-end Service code file, including: for the index annotation indication in the table view object and the upload and download function indication in the table view object, through the back-end Service file template, generating the back-end Service code with index information and upload and download functions; the table view object is loaded into the Controller file template for connecting the front-end and back-end included in the front-end and back-end code templates in the table configuration information through the template engine to generate the front-end Controller code file, including: for the upload and download function indication in the table view object, through the Controller file template connecting the front-end and back-end, generating the front-end Controller code with HTTP interface.
[0205] For details of the content of this part, please refer to the content of step 104 in the above embodiment.
[0206] Based on the same concept, the embodiment of the present application provides a device for generating front-end and back-end code files for accessing a database, such as Figure 4 , which is a schematic diagram of a device for generating front-end and back-end code files for accessing a database provided in an embodiment of the present application, the device includes a reading unit 401, an acquisition unit 402, a creation unit 403 and a generation unit 404;
[0207] The reading unit 401 is used to read a database configuration file; the database configuration file includes database connection information and table configuration information of each data table; wherein the table configuration information is provided with various configuration information of the front-end and back-end code files for generating the data table;
[0208] The acquisition unit 402 is used to acquire, for any data table in the accessed 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;
[0209] A creation unit 403 is used 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 object includes column view objects, at least one column view object includes annotation information of a column field, and the annotation information is used to set restrictions on the field value of the column field during the front-end and back-end interaction process;
[0210] The generating unit 404 is used to generate various code files for the data table at the front-end and back-end according to the table view object and the preset front-end and back-end code templates.
[0211] Further, for the device, the creation unit 403 is specifically used to: create an initial table view object; the initial table view object includes multiple pending members; for any column field in the column members of the multiple pending members, create a column view object of the column field; if the table description information of the data table and / or the table configuration information of the data table contains annotation information of the column field, then add an indication corresponding to the annotation information to the column view object, thereby generating a table view object of the data table.
[0212] Further, for the device, a creation unit 403 is specifically used to: if the dictionary information of the column field is obtained from the table description information of the data table, a dictionary annotation indication is added to the column view object, and the dictionary annotation indication and the dictionary information are added to the data dictionary; the dictionary annotation indication is used to obtain the dictionary information of the column field from the data dictionary.
[0213] Further, for the device, a creation unit 403 is specifically used to: if the index information of the column field is obtained from the table description information of the data table, then an index annotation indication is added in the column view object; wherein, if the index information is a primary key index, then the information of the primary key strategy member is set in the table view object.
[0214] Further, for the device, a creation unit 403 is specifically used to: if the verification information of the column field is obtained from the table description information of the data table and / or the table configuration information of the data table, a verification annotation indication is added to the column view object; the verification annotation indication is used to indicate the verification class of the column field.
[0215] Further, for the device, the generation unit 404 is specifically used to: load the table view object into the backend DTO file template included in the frontend and backend code templates in the table configuration information through the template engine to generate a backend DTO code file; load the table view object into the backend POJO file template included in the frontend and backend code templates in the table configuration information through the template engine to generate a backend POJO code file; load the table view object into the backend Mapper file template included in the frontend and backend code templates in the table configuration information through the template engine to generate a backend Mapper code file; load the table view object into the backend Service file template included in the frontend and backend code templates in the table configuration information through the template engine to generate a backend Service code file; load the table view object into the Controller file template connecting the frontend and backend included in the frontend and backend code templates in the table configuration information through the template engine to generate a frontend and backend Controller code file.
[0216] Further, for the device, the generation unit 404 is specifically used to: for each column view object, based on the back-end DTO file template, when the primary key field of the column view object is consistent with the primary key field of the table view object, generate a back-end DTO code with a primary key annotation; for a field with a value constraint, generate a back-end DTO code with a value annotation; for a field with a dictionary annotation indication, generate a back-end DTO code with a dictionary annotation indication; for an index annotation indication in the table view object, generate a back-end POJO code with index information through a back-end POJO file template; for an index annotation indication in the table view object, generate a back-end Mapper code for database operations with index information through a back-end Mapper file template; for an index annotation indication in the table view object and an upload and download function indication in the table view object, generate a back-end Service code with index information and upload and download functions through a back-end Service file template; for an upload and download function indication in the table view object, generate front-end and back-end Controller codes with HTTP interfaces through a Controller file template that connects the front-end and back-end.
[0217] The embodiment of the present application also provides a computing device, which may be a desktop computer, a portable computer, a smart phone, a tablet computer, a personal digital assistant (PDA), etc. The computing device may include a central processing unit (CPU), a memory, an input / output device, etc. The input device may include a keyboard, a mouse, a touch screen, etc. The output device may include a display device, such as a liquid crystal display (LCD), a cathode ray tube (CRT), etc.
[0218] The memory may include a read-only memory (ROM) and a random access memory (RAM), and provides the processor with program instructions and data stored in the memory. In an embodiment of the present application, the memory may be used to store program instructions for a method of generating front-end and back-end code files for accessing a database;
[0219] The processor is used to call the program instructions stored in the memory and execute the method for generating the front-end and back-end code files for accessing the database according to the obtained program.
[0220] like Figure 5 FIG. 1 is a schematic diagram of a computing device provided in an embodiment of the present application, wherein the computing device includes:
[0221] Processor 501, memory 502, transceiver 503, bus interface 504; wherein the processor 501, memory 502 and transceiver 503 are connected via a bus 505;
[0222] The processor 501 is used 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;
[0223] The processor 501 may be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and a NP. It may also be 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 generic array logic (GAL), or any combination thereof.
[0224] The memory 502 is used to store one or more executable programs and can store data used by the processor 501 when performing operations.
[0225] Specifically, the program may include program code, and the program code includes computer operation instructions. The memory 502 may include volatile memory, such as random-access memory (RAM); the memory 502 may also include non-volatile memory, such as flash memory, hard disk drive (HDD) or solid-state drive (SSD); the memory 502 may also include a combination of the above-mentioned types of memory.
[0226] The memory 502 stores the following elements, executable modules or data structures, or a subset thereof, or an extended set thereof:
[0227] Operation instructions: include various operation instructions, used to implement various operations.
[0228] Operating system: includes various system programs used to implement various basic businesses and handle hardware-based tasks.
[0229] The bus 505 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0230] 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.
[0231] An embodiment of the present application also provides a computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute a method for generating front-end and back-end code files for accessing a database.
[0232] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0233] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0234] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0235] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0236] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0237] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these 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 also intended to include these modifications and variations.< / t> < / t> < / t> < / x>
Claims
1. A method for generating front-end and back-end code files for accessing a database, characterized in that: include: Reading a database configuration file; the database configuration file includes database connection information and table configuration information of each data table; wherein the table configuration information is provided with various configuration information of the front-end and back-end code files for generating the data table; For any data table among the data tables, obtain 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 object includes column view objects, at least one column view object includes annotation information of a column field, and the annotation information is used to set restrictions on field values of the column field during front-end and back-end interaction; Generate the front-end and back-end code files for the data table according to the table view object and the preset front-end and back-end code templates; The step of 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 includes a plurality of pending members; For any column field in the column members of the plurality of pending members, create a column view object of the column field; If the table description information of the data table and / or the table configuration information of the data table contains annotation information of the column field, an indication corresponding to the annotation information is added to the column view object, thereby generating a table view object of the data table.
2. The method according to claim 1, characterized in that The adding the indication corresponding to the annotation information to the column view object includes: If the dictionary information of the column field is obtained from the table description information of the data table, a dictionary annotation indication is added to the column view object, and the dictionary annotation indication and the dictionary information are added to the data dictionary; the dictionary annotation indication is used to obtain the dictionary information of the column field from the data dictionary.
3. The method according to claim 1, characterized in that The adding the indication corresponding to the annotation information to the column view object includes: If the index information of the column field is obtained from the table description information of the data table, an index annotation indication is added to the column view object; wherein, if the index information is a primary key index, information of the primary key strategy member is set in the table view object.
4. The method according to claim 1, characterized in that The adding the indication corresponding to the annotation information to the column view object includes: If the verification information of the column field is obtained from the table description information of the data table and / or the table configuration information of the data table, a verification annotation indication is added to the column view object; the verification annotation indication is used to indicate the verification class of the column field.
5. The method according to any one of claims 1 to 4, characterized in that: The generating of the front-end and back-end code files for the data table according to the table view object and the preset front-end and back-end code templates includes: Through the template engine, the table view object is loaded into the backend DTO file template included in the front-end and back-end code templates in the table configuration information to generate a backend DTO code file; By means of a template engine, the table view object is loaded into a backend POJO file template included in the frontend and backend code templates in the table configuration information to generate a backend POJO code file; Through the template engine, the table view object is loaded into the backend Mapper file template included in the front-end and back-end code templates in the table configuration information to generate a backend Mapper code file; By means of a template engine, the table view object is loaded into a backend Service file template included in the frontend and backend code templates in the table configuration information to generate a backend Service code file; Through the template engine, the table view object is loaded into the Controller file template connecting the front-end and back-end included in the front-end and back-end code templates in the table configuration information to generate the front-end and back-end Controller code files.
6. The method according to claim 5, characterized in that The table view object is loaded into the backend DTO file template included in the front-end and back-end code templates in the table configuration information through the template engine to generate a backend DTO code file, including: For each column view object, based on the backend DTO file template, when the primary key field of the column view object is consistent with the primary key field of the table view object, generate the backend DTO code with the primary key annotation; for the field with value constraints, generate the backend DTO code with the value annotation; for the field with the dictionary annotation indication, generate the backend DTO code with the dictionary annotation indication; The table view object is loaded into the backend POJO file template included in the front-end and back-end code templates in the table configuration information through the template engine to generate a backend POJO code file, including: According to the index annotation instructions in the table view object, the backend POJO code with index information is generated through the backend POJO file template; The table view object is loaded into the backend Mapper file template included in the front-end and back-end code templates in the table configuration information through the template engine to generate a backend Mapper code file, including: Based on the index annotation instructions in the table view object, the backend Mapper code for database operations with index information is generated through the backend Mapper file template; The table view object is loaded into the backend Service file template included in the front-end and back-end code templates in the table configuration information through the template engine to generate a backend Service code file, including: For the index annotation indication in the table view object and the upload and download function indication in the table view object, generate the backend Service code with index information and upload and download functions through the backend Service file template; The table view object is loaded into the Controller file template for connecting the front-end and back-end included in the front-end and back-end code templates in the table configuration information through the template engine to generate a front-end Controller code file, including: According to the upload and download function instructions in the table view object, the front-end and back-end Controller code with HTTP interface is generated by connecting the front-end and back-end Controller file templates.
7. A device for generating front-end and back-end code files for accessing a database, characterized in that: include: A reading unit, used to read a database configuration file; the database configuration file includes database connection information and table configuration information of each data table; wherein the table configuration information is provided with various configuration information of the front-end and back-end code files used to generate the data table; An acquisition unit, configured to acquire, for any data table among the 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 creation unit, 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 object includes column view objects, at least one column view object includes annotation information of a column field, and the annotation information is used to set restrictions on field values of the column field during the front-end and back-end interaction process; A generating unit, configured to generate respective code files at the front-end and back-end for the data table according to the table view object and preset front-end and back-end code templates; The creation unit is specifically used to create an initial table view object; the initial table view object includes multiple pending members; for any column field in the column members of the multiple pending members, a column view object of the column field is created; 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, an indication corresponding to the annotation information is added to the column view object, thereby generating a table view object of the data table.
8. A computer device, characterized in that: include: Memory for storing computer programs; A processor, configured to call a computer program stored in the memory, and execute the method according to any one of claims 1 to 6 according to the obtained program.
9. A computer-readable storage medium, characterized in that: The storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method and system for generating front-end and back-end codes
CN112596719A
Method and platform for implementing graphical code-free software development, computer device and storage medium
WO2021217661A1