CN108595162B - Code generation method and device - Google Patents
Code generation method and device Download PDFInfo
- Publication number
- CN108595162B CN108595162B CN201810231679.3A CN201810231679A CN108595162B CN 108595162 B CN108595162 B CN 108595162B CN 201810231679 A CN201810231679 A CN 201810231679A CN 108595162 B CN108595162 B CN 108595162B
- Authority
- CN
- China
- Prior art keywords
- database
- field information
- attribute information
- information
- java attribute
- 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.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computing Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
The embodiment of the invention provides a code generation method and a device, wherein the method comprises the following steps: acquiring one or more database field information in a target database table according to a received user instruction; mapping one or more database field information according to a preset mapping rule to acquire corresponding one or more JAVA attribute information; and automatically generating a database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information. Therefore, the code generation method applicable to Spring JDBC is provided, the generated JAVA attribute information and the database statements are universal, and an operator can apply the generated JAVA attribute information and the generated database statements to various scenes, so that the flexibility of code generation and the user experience are effectively improved.
Description
Technical Field
The embodiment of the invention relates to the field of communication, in particular to a code generation method and a code generation device.
Background
During the use of the database, the JAVA programmer usually needs to read the relevant information in the database through JDBC tool. Related modules in JDBC tools, for example: and the code generator can generate database statements according to tables and fields in the database.
JDBC tools in the prior art, for example: hibernate, mybases and the like generally directly convert tables and fields in a database through configuration files, write the tables and the fields into database statements, package the database statements, and directly output the packaged files to a hard disk. However, since the database statement generated in this way can only be applied to the corresponding JDBC tool, but has no generality, the method in the prior art cannot be applied to the Spring JDBC tool. Moreover, because the code generation method in the prior art is one-time generation, if an operator needs to change a statement, a large amount of modification needs to be performed on a configuration file, which results in poor user experience.
Disclosure of Invention
The embodiment of the invention provides a code generation method, and aims to solve the problems that a code generation method in the prior art is not universal, cannot be applied to a Spring JDBC tool, is difficult to change due to the fact that a generated result is a packaged file, is lack of flexibility, causes poor user experience and the like.
In order to solve the above problem, the present invention discloses a code generation method, including:
acquiring one or more database field information in a target database table according to a received user instruction;
mapping one or more database field information according to a preset mapping rule to acquire corresponding one or more JAVA attribute information;
and automatically generating a database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information.
According to another aspect of the present invention, there is provided a code generating apparatus including:
the acquisition module is used for acquiring one or more database field information in a target database table according to the received user instruction;
the mapping module is used for mapping one or more database field information according to a preset mapping rule so as to acquire one or more corresponding JAVA attribute information;
and the generating module is used for automatically generating database statements corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information.
Compared with the prior art, the method and the device have the advantages that one or more database field information in the target database table is obtained according to the received user instruction; mapping one or more database field information according to a preset mapping rule to acquire corresponding one or more JAVA attribute information; and automatically generating a database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information. Therefore, the code generation method applicable to Spring JDBC is provided, the generated JAVA attribute information and the database statements are universal, and an operator can apply the generated JAVA attribute information and the generated database statements to various scenes, so that the flexibility of code generation and the user experience are effectively improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive labor.
FIG. 1 is a flow diagram of a code generation method of an embodiment of the present invention;
FIG. 2 is a flowchart illustrating specific steps of a code generation method according to an embodiment of the present invention;
FIG. 3 is a block diagram of a code generation apparatus according to an embodiment of the present invention;
FIG. 4 is a second block diagram of a code generation apparatus according to an embodiment of the present invention;
FIG. 5 is a third block diagram of a code generation apparatus according to an embodiment of the present invention;
fig. 6 is a fourth block diagram of a code generation apparatus according to an embodiment of the present invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
Example one
Referring to fig. 1, a flowchart of a code generation method according to an embodiment of the present invention is shown, which may specifically include the following steps:
Specifically, in the embodiment of the present invention, the code generation apparatus may be applied to a Spring JDBC tool. The code generation device receives the user instruction and acquires a target data dictionary in the local database, namely, one or more database field information in a target database table according to the user instruction.
Specifically, in the embodiment of the present invention, the code generation apparatus is preset with a mapping rule, and an operator may set the mapping rule according to actual requirements.
In an embodiment of the present invention, the code generation apparatus may map the acquired one or more database field information according to a preset mapping rule to acquire corresponding one or more JAVA attribute information.
Step 103, automatically generating a database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information.
Specifically, in the embodiment of the present invention, the code generation apparatus automatically generates the database statement corresponding to the database table according to the acquired one or more database field information and the acquired one or more JAVA attribute information through mapping. The operator can copy the database statement or the JAVA attribute information to be applied to each application scenario.
In summary, in the technical solution of the embodiment of the present invention, one or more database field information in a target database table is obtained according to a received user instruction; mapping one or more database field information according to a preset mapping rule to acquire corresponding one or more JAVA attribute information; and automatically generating a database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information. Therefore, the code generation method applicable to Spring JDBC is provided, the generated JAVA attribute information and the database statements are universal, and an operator can apply the generated JAVA attribute information and the generated database statements to various scenes, so that the flexibility of code generation and the user experience are effectively improved.
Example two
Referring to fig. 2, a flowchart of a code generation method according to an embodiment of the present invention is shown, which may specifically include the following steps:
Specifically, in the embodiment of the present invention, the code generation apparatus may be applied to a Spring JDBC tool. And the code generation device in the embodiment of the invention provides a user interaction page, and a user selects a database table needing to generate a database statement on the user interaction page so as to trigger a user instruction.
The user interaction page provided by the embodiment of the invention ensures that the code generation device in the embodiment of the invention is more friendly, and the mode of selecting the interaction page to replace the mode of a command line in the prior art effectively reduces the complexity of user operation and improves the operation accuracy.
Specifically, in the embodiment of the present invention, the code generation apparatus receives a user instruction, traverses one or more database tables stored in the local database according to the user instruction, and invokes the target database table.
Specifically, in an embodiment of the present invention, the code generation apparatus extracts one or more database field information in the target database table. In an embodiment of the present invention, the database field information includes a database field name and a database field type.
And 204, matching the database field information with one or more mapping items in a preset mapping rule, wherein the mapping items are corresponding relations between the digital library field information and JAVA attribute information.
Specifically, in the embodiment of the present invention, the code generation apparatus matches the extracted one or more database field information with one or more mapping entries in a preset mapping rule.
Specifically, in the embodiment of the present invention, an operator may set a mapping item in the mapping rule according to different databases, that is, the operator may set a corresponding relationship between database field information in the mapping item and JAVA attribute information according to actual requirements, so that the code generation method in the embodiment of the present invention may be applied to different databases. In an embodiment of the present invention, the JAVA attribute information includes a JAVA attribute name and a JAVA attribute type.
And step 205, obtaining the JAVA attribute information corresponding to the successfully matched database field information.
In the embodiment of the present invention, the code generation apparatus matches the database field name with the mapping entry, and if there is a mapping entry including the database field name, it is determined that the matching is successful. And the code generation device acquires the JAVA attribute name in the mapping item corresponding to the successfully matched database field name. Similarly, the code generation device matches the database field type with the mapping item, and if the mapping item containing the database field type exists, the matching is determined to be successful. And the code generation device acquires the JAVA attribute type in the mapping item corresponding to the successfully matched database field type.
According to the method, the field names of the database are mapped into JAVA attribute names, and the field types of the database are mapped into JAVA attribute types, so that an operator can directly use the mapped JAVA attribute information and apply the JAVA attribute information to other application scenes, and the universality of code generation is realized.
And in an embodiment of the invention, the JAVA attribute information can be displayed at the designated position of the user interaction page, and an operator can acquire the JAVA attribute information directly by copying, so that the convenience of the code generation method is further improved.
Specifically, in the embodiment of the present invention, the code generation apparatus calls a configuration table stored locally to obtain a preset default statement of the database. In one embodiment of the invention, the default statement of the database is an add-delete modify statement in SQL (Structured Query Language). And the variable in the default statement of the database is a default variable or null.
Specifically, in the embodiment of the present invention, the code generation apparatus updates the default statement of the database according to the field information of the database and the JAVA attribute information. That is, the field name and the field type in the database field information, and the attribute name and the attribute type in the JAVA attribute information are filled in the corresponding positions in the default statement of the database, so that the default values of the variables in the default statement are modified to generate the database statement.
In the embodiment of the invention, the generated database statement is displayed at the designated position of the user interaction interface, so that an operator can copy the required database statement only by simple mouse selection operation, and the copied database statement is applied to various scenes, thereby realizing the convenience and the easy operability of the code generation method. In addition, the user can correspondingly modify the copied database statements according to different application scenes, so that the practicability of code generation is further improved.
In summary, in the technical solution of the embodiment of the present invention, one or more database field information in a target database table is obtained according to a received user instruction; mapping one or more database field information according to a preset mapping rule to acquire corresponding one or more JAVA attribute information; and automatically generating a database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information. Therefore, the code generation method applicable to Spring JDBC is provided, the generated JAVA attribute information and the database statements are universal, and an operator can apply the generated JAVA attribute information and the generated database statements to various scenes, so that the flexibility of code generation and the user experience are effectively improved.
EXAMPLE III
Referring to fig. 3, a block diagram of a code generation apparatus according to an embodiment of the present invention is shown, where the apparatus may specifically include the following modules:
an obtaining module 301, configured to obtain one or more database field information in a target database table according to a received user instruction;
the mapping module 302 is configured to map one or more database field information according to a preset mapping rule to obtain one or more corresponding JAVA attribute information;
the generating module 303 is configured to automatically generate a database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information.
As shown in fig. 4, in a preferred embodiment of the present invention, on the basis of fig. 3, the obtaining module 301 further includes:
the receiving sub-module 3011 is configured to receive a user instruction triggered by a user on a user interaction page;
the first calling sub-module 3012 is configured to call a target database table from one or more database tables stored in the local database according to a user instruction;
and the extraction sub-module 3013 is used for extracting one or more database field information in the target database table.
As shown in fig. 5, in a preferred embodiment of the present invention, on the basis of fig. 3, the mapping module 302 further includes:
the matching submodule 3021 is configured to match the database field information with one or more mapping items in a preset mapping rule, where the mapping items are corresponding relationships between the digital library field information and JAVA attribute information;
the obtaining sub-module 3022 is configured to obtain JAVA attribute information corresponding to the successfully matched database field information.
As shown in fig. 6, in a preferred embodiment of the present invention, on the basis of fig. 3, the generating module 303 further includes:
a second calling submodule 3031, configured to call a preset database default statement;
the updating submodule 3032 is configured to update the database default statement according to the one or more database field information and the one or more JAVA attribute information, so as to generate the database statement.
In summary, the apparatus in the embodiment of the present invention obtains one or more database field information in a target database table according to a received user instruction; mapping one or more database field information according to a preset mapping rule to acquire corresponding one or more JAVA attribute information; and automatically generating a database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information. Therefore, the code generation method applicable to Spring JDBC is provided, the generated JAVA attribute information and the database statements are universal, and an operator can apply the generated JAVA attribute information and the generated database statements to various scenes, so that the flexibility of code generation and the user experience are effectively improved.
For the apparatus embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
Embodiments of the invention may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above detailed description is provided for a code generation method and apparatus provided by the present invention, and a specific example is applied in the present document to explain the principle and the implementation of the present invention, and the description of the above embodiment is only used to help understanding the method and the core idea of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.
Claims (8)
1. A code generation method applied to a Spring JDBC tool includes:
acquiring one or more database field information in a target database table according to a received user instruction; the target database table is used for generating database statements;
mapping the one or more database field information according to a preset mapping rule to acquire corresponding one or more JAVA attribute information;
automatically generating a database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information; the method comprises the following steps: filling the database field information and the JAVA attribute information into corresponding positions in a database default statement to generate a database statement;
wherein, the step of mapping the one or more database field information according to a preset mapping rule to obtain the corresponding one or more JAVA attribute information specifically includes:
matching the database field information with one or more mapping items in the preset mapping rule, wherein the mapping items are corresponding relations between the digital library field information and JAVA attribute information;
and obtaining JAVA attribute information corresponding to the successfully matched database field information.
2. The method of claim 1, wherein the step of obtaining one or more database field information in the target database table according to the received user instruction specifically comprises:
receiving the user instruction triggered by the user on the user interaction page;
calling the target database table from one or more database tables stored in a local database according to the user instruction;
one or more database field information in the target database table is extracted.
3. The method according to claim 1, wherein the step of automatically generating the database statement corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information comprises:
calling a preset database default statement;
updating the database default statement according to the one or more database field information and the one or more JAVA attribute information to generate the database statement.
4. The method of any of claims 1 to 3, wherein the database field information comprises a database field name and a database field type;
the JAVA attribute information includes a JAVA attribute name and a JAVA attribute type.
5. A code generation apparatus applied to a Spring JDBC tool, comprising:
the acquisition module is used for acquiring one or more database field information in a target database table according to the received user instruction; the target database table is used for generating database statements;
the mapping module is used for mapping the one or more database field information according to a preset mapping rule so as to acquire corresponding one or more JAVA attribute information;
the generating module is used for automatically generating database statements corresponding to the database table according to the one or more database field information and the one or more JAVA attribute information; the method comprises the following steps: filling the database field information and the JAVA attribute information into corresponding positions in a database default statement to generate a database statement;
wherein the mapping module comprises:
the matching submodule is used for matching the field information of the database with one or more mapping items in the preset mapping rule, wherein the mapping items are corresponding relations between the field information of the digital library and JAVA attribute information;
and the obtaining submodule is used for obtaining the JAVA attribute information corresponding to the successfully matched database field information.
6. The apparatus of claim 5, wherein the obtaining module further comprises:
the receiving submodule is used for receiving the user instruction triggered by the user on the user interaction page;
the first calling submodule is used for calling the target database table from one or more database tables stored in a local database according to the user instruction;
and the extraction submodule is used for extracting one or more database field information in the target database table.
7. The apparatus of claim 5, wherein the generating module further comprises:
the second calling submodule is used for calling a preset database default statement;
and the updating submodule is used for updating the default statement of the database according to the field information of the one or more databases and the one or more JAVA attribute information so as to generate the database statement.
8. The apparatus of any of claims 5 to 7, wherein the database field information comprises a database field name and a database field type;
the JAVA attribute information includes a JAVA attribute name and a JAVA attribute type.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810231679.3A CN108595162B (en) | 2018-03-20 | 2018-03-20 | Code generation method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810231679.3A CN108595162B (en) | 2018-03-20 | 2018-03-20 | Code generation method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108595162A CN108595162A (en) | 2018-09-28 |
CN108595162B true CN108595162B (en) | 2022-04-05 |
Family
ID=63626942
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810231679.3A Active CN108595162B (en) | 2018-03-20 | 2018-03-20 | Code generation method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108595162B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109408057B (en) * | 2018-10-23 | 2022-03-04 | 网易传媒科技(北京)有限公司 | Method, device, medium and computing equipment for automatically generating codes |
CN110837363A (en) * | 2019-11-05 | 2020-02-25 | 北京锐安科技有限公司 | Code file generation method, device, equipment and medium |
CN112800150A (en) * | 2021-02-25 | 2021-05-14 | 浪潮云信息技术股份公司 | Automatic mapping and table building method for heterogeneous database |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102841889A (en) * | 2011-06-20 | 2012-12-26 | 中兴通讯股份有限公司 | Method and device for achieving efficient database access based on ORM (object relational mapping) architecture |
CN103530425A (en) * | 2013-11-01 | 2014-01-22 | 哈尔滨商业大学 | Android terminal remote data base access code generation system and method based on object dependence mapping |
CN105677323A (en) * | 2015-12-31 | 2016-06-15 | 合肥大多数信息科技有限公司 | Method for automatically generating database operation layer codes |
CN106469064A (en) * | 2016-09-04 | 2017-03-01 | 深圳市云智易联科技有限公司 | Code generating method and code generating unit |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7149730B2 (en) * | 2002-05-03 | 2006-12-12 | Ward Mullins | Dynamic class inheritance and distributed caching with object relational mapping and cartesian model support in a database manipulation and mapping system |
-
2018
- 2018-03-20 CN CN201810231679.3A patent/CN108595162B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102841889A (en) * | 2011-06-20 | 2012-12-26 | 中兴通讯股份有限公司 | Method and device for achieving efficient database access based on ORM (object relational mapping) architecture |
CN103530425A (en) * | 2013-11-01 | 2014-01-22 | 哈尔滨商业大学 | Android terminal remote data base access code generation system and method based on object dependence mapping |
CN105677323A (en) * | 2015-12-31 | 2016-06-15 | 合肥大多数信息科技有限公司 | Method for automatically generating database operation layer codes |
CN106469064A (en) * | 2016-09-04 | 2017-03-01 | 深圳市云智易联科技有限公司 | Code generating method and code generating unit |
Also Published As
Publication number | Publication date |
---|---|
CN108595162A (en) | 2018-09-28 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10095499B2 (en) | Optimization for multi-project package manager | |
CN107918666B (en) | Data synchronization method and system on block chain | |
US9146955B2 (en) | In-memory, columnar database multidimensional analytical view integration | |
CN108874924B (en) | Method and device for creating search service and computer-readable storage medium | |
CN108595162B (en) | Code generation method and device | |
CN109033406B (en) | Method, apparatus and storage medium for searching blockchain data | |
CN107391101B (en) | Information processing method and device | |
CN109710220B (en) | Relational database query method, relational database query device, relational database query equipment and storage medium | |
US7325240B2 (en) | Method for generating calling convention transformation process | |
CN110109981B (en) | Information display method and device for work queue, computer equipment and storage medium | |
CN113515564B (en) | J2 EE-based data access method, device, equipment and storage medium | |
US8413109B2 (en) | Systems and methods for metamodel transformation | |
CN111274263A (en) | Visual database change statement generation method and device and storage medium | |
EP2924565A1 (en) | Web-application-launch application programming interface | |
US20060015483A1 (en) | SQL query enhancement technique | |
US9411618B2 (en) | Metadata-based class loading using a content repository | |
CN113721973A (en) | Configuration file generation method, device, equipment and medium | |
US20220229858A1 (en) | Multi-cloud object store access | |
KR100545348B1 (en) | An integrated development system for a SyncML server application development | |
CN108491448B (en) | Data pushing method and device | |
CN108334621B (en) | Database operation method, device, equipment and computer readable storage medium | |
US10789235B2 (en) | Base user defined functions | |
CN114416727B (en) | Data processing method, device, electronic equipment and storage medium | |
Brown | Introduction to UTL_HTTP | |
KR20210041781A (en) | An integrated development system for a SyncML serverapplication development |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
TR01 | Transfer of patent right |
Effective date of registration: 20230625 Address after: 201401 floor 12, building 2, No. 1919, Baziqiao Road, Nanqiao Town, Fengxian District, Shanghai Patentee after: Zhiche (Shanghai) Industrial Co.,Ltd. Address before: 100013 no.2-c1, block a, Chuangxin building, 11 Hepingli East Street, Dongcheng District, Beijing (2 / F above ground) Patentee before: BEIJING VCYBER TECHNOLOGY Co.,Ltd. |
|
TR01 | Transfer of patent right |