CN108121542B - MyBatis-based SQL statement configuration method and system - Google Patents
MyBatis-based SQL statement configuration method and system Download PDFInfo
- Publication number
- CN108121542B CN108121542B CN201711143542.4A CN201711143542A CN108121542B CN 108121542 B CN108121542 B CN 108121542B CN 201711143542 A CN201711143542 A CN 201711143542A CN 108121542 B CN108121542 B CN 108121542B
- Authority
- CN
- China
- Prior art keywords
- mybatis
- sql
- configuration file
- database
- framework
- 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/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/242—Query formulation
- G06F16/2433—Query languages
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Mathematical Physics (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Stored Programmes (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
A configuration method and a system of SQL statements based on MyBatis comprise a MyBatis framework, a core configuration file, a mapping configuration file and a database, and comprise a process that the MyBatis framework operates the database: step A: introducing a MyBatis framework dependency library and a database driver into a java project; and B: compiling the core configuration file; and C: creating a mapping configuration file, transmitting the SQL sentence serving as a parameter into a MyBatis framework by the mapping configuration file, and performing parameter analysis on the SQL sentence and executing operation on a database by the MyBatis framework; step D: according to different types of databases, SQL sentences are formulated through IDs, the configured SQL sentences are read and executed, and finally results are obtained. The invention solves the problem that when MyBatis is used, multiple complicated configurations are needed when SQL is configured, and realizes the effects of shortening development time, increasing development flexibility and improving development efficiency.
Description
Technical Field
The invention relates to the technical field of SQL processing of MyBatis frameworks, in particular to a method and a system for configuring an SQL statement based on MyBatis.
Background
MyBatis is a java-based persistent layer framework that supports customized SQL, storage procedures, and advanced mapping. MyBAtis avoids almost all JDBC code and manual setting of parameters and acquisition of result sets. MyBAtis can use simple XML or annotations to configure and map the native information, mapping the interfaces and java's pojs to records in the database.
In the process of using MyBAtis, each time a new SQL statement is used, whether a corresponding mapping file and an entity class corresponding to a data table exist or not needs to be checked, if not, the mapping file and the entity class need to be created, and SQL and related settings are configured in the corresponding file, so that the configuration process is very complicated.
Disclosure of Invention
The invention aims to provide a method and a system for configuring SQL sentences based on MyBatis, which solve the problem that a plurality of complex configurations are required when the SQL is configured when MyBatis is used by using an SQL sentence parameter analysis function of the MyBatis, and achieve the effects of shortening development time, increasing development flexibility and improving development efficiency.
In order to achieve the purpose, the invention adopts the following technical scheme:
a configuration method of SQL statements based on MyBatis comprises a MyBatis framework, a core configuration file, a mapping configuration file and a database, and comprises the process that the MyBatis framework operates the database:
step A: introducing the MyBatis framework dependency library and the drive of the database into a java project;
and B: writing the core configuration file;
and C: creating the mapping configuration file, wherein the mapping configuration file transmits SQL sentences serving as parameters into the MyBatis framework, and the MyBatis framework performs parameter analysis on the SQL sentences and executes operation on the database;
step D: and formulating SQL sentences through IDs according to the databases of different types, reading the configured SQL sentences and executing the sentences, and finally obtaining results.
Preferably, the method comprises the parsing process of the MyBatis framework on the SQL statement:
step C1: the mapping configuration file transmits SQL sentences serving as parameters into the MyBatis framework;
step C2: the MyBatis framework judges the SQL sentence transmitted in and judges the type of the SQL sentence;
step C3: if the type of the SQL statement as the parameter is the query type, returning a list, wherein each element on the list is a map object; if the type of the SQL statement as the parameter is the modification type, directly returning the number of the affected records.
Preferably, the core configuration file is an XML file for configuring global information, and includes a user name, a password, a link of the database, and drive information selected by the database.
Preferably, the mapping configuration file is an XML file configuring the ORM mapping relationship and the SQL statement.
A system of a MyBatis-based SQL statement configuration method comprises a MyBatis framework, a core configuration file, a mapping configuration file and a database, wherein the MyBatis framework is used for carrying out a database operation module for configuring the database;
introducing the MyBatis framework dependency library and the drive of the database into a java project;
writing the core configuration file;
creating the mapping configuration file, wherein the mapping configuration file transmits SQL sentences serving as parameters into the MyBatis framework, and the MyBatis framework performs parameter analysis on the SQL sentences and executes operation on the database;
and formulating SQL sentences through IDs according to the databases of different types, reading the configured SQL sentences and executing the sentences, and finally obtaining results.
Preferably, the system comprises an analysis module of the mybatis framework for the SQL statement, and the analysis module is used for analyzing the SQL statement;
the mapping configuration file transmits SQL sentences serving as parameters into the MyBatis framework;
the MyBatis framework judges the SQL sentence transmitted in and judges the type of the SQL sentence;
if the type of the SQL statement as the parameter is the query type, returning a list, wherein each element on the list is a map object; if the type of the SQL statement as the parameter is the modification type, directly returning the number of the affected records.
Compared with the prior art, the method reduces the steps of establishing the class object corresponding to the database table structure to realize the ORM mapping, and also has the mapping file configuration different from the prior art, wherein the configuration mapping file generally corresponds to one table (or class object) and one file. In which SQL statements and other related settings that need to be executed are configured. In the process of using MyBatis, each time a new SQL statement is used, whether an entity class corresponding to a corresponding mapping file and a corresponding data table exists or not needs to be checked, and if the entity class does not exist, the entity class needs to be created. At present, multiple configurations are not needed, SQL sentences are input into the MyBatis framework as parameters, the parameter analysis function of the MyBatis framework is utilized to automatically select and configure, development time is shortened, development efficiency is improved, the trouble of configuring entity classes is avoided, the entity classes do not need to be modified when a data table structure is adjusted, and flexibility is provided for project maintenance.
Drawings
FIG. 1 is a flow chart of the operation of the MyBatis framework database of the present invention;
FIG. 2 is a flow chart of the present invention for parsing SQL statement by the MyBatis framework.
Wherein: MyBatis framework 1, core configuration file 2, mapping configuration file 3 and database 4.
Detailed Description
The technical scheme of the invention is further explained by the specific implementation mode in combination with the attached drawings.
A configuration method of a MyBatis-based SQL statement, includes a MyBatis framework 1, a core configuration file 2, a mapping configuration file 3, and a database 4, and includes a process of the MyBatis framework 1 operating the database 4, as shown in fig. 1:
step A: introducing the MyBatis framework 1 dependency library and the drive of the database 4 into a java project;
and B: writing the core configuration file 2;
and C: creating the mapping configuration file 3, wherein the mapping configuration file 3 transmits SQL statements serving as parameters into the MyBatis framework 1, and the MyBatis framework 1 performs parameter analysis on the SQL statements and executes operation on the database 4;
step D: according to the databases 4 of different types, SQL sentences are formulated through IDs, the configured SQL sentences are read and executed, and finally results are obtained.
Preferably, as shown in fig. 2, the method includes a parsing process of the MyBatis framework 1 on the SQL statement:
step C1: the mapping configuration file 3 transmits SQL sentences serving as parameters into the MyBatis framework 1;
step C2: the MyBatis framework 1 judges the transmitted SQL statement and judges the type of the SQL statement;
step C3: if the type of the SQL statement as the parameter is the query type, returning a list, wherein each element on the list is a map object; if the type of the SQL statement as the parameter is the modification type, directly returning the number of the affected records.
Preferably, the core configuration file 2 is an XML file configured with global information, and includes a user name, a password, a link of the database, and drive information selected by the database.
Preferably, the mapping configuration file 3 is an XML file for configuring the ORM mapping relationship and the SQL statement.
A system of a MyBatis-based SQL statement configuration method comprises a MyBatis framework 1, a core configuration file 2, a mapping configuration file 3 and a database 4, wherein the MyBatis framework 1 is used for carrying out an operation module of the database 4 and is used for configuring the database 4;
introducing the MyBatis framework 1 dependency library and the drive of the database 4 into a java project;
writing the core configuration file 2;
creating the mapping configuration file 3, wherein the mapping configuration file 3 transmits SQL statements serving as parameters into the MyBatis framework 1, and the MyBatis framework 1 performs parameter analysis on the SQL statements and executes operation on the database 4;
according to the databases 4 of different types, SQL sentences are formulated through IDs, the configured SQL sentences are read and executed, and finally results are obtained.
Preferably, the system comprises an analysis module of the mybatis framework 1 for the SQL statement, and the analysis module is used for analyzing the SQL statement;
the mapping configuration file 3 transmits SQL sentences serving as parameters into the MyBatis framework 1;
the MyBatis framework 1 judges the transmitted SQL statement and judges the type of the SQL statement;
if the type of the SQL statement as the parameter is the query type, returning a list, wherein each element on the list is a map object; if the type of the SQL statement as the parameter is the modification type, directly returning the number of the affected records.
The technical principle of the present invention is described above in connection with specific embodiments. The description is made for the purpose of illustrating the principles of the invention and should not be construed in any way as limiting the scope of the invention. Based on the explanations herein, those skilled in the art will be able to conceive of other embodiments of the present invention without inventive effort, which would fall within the scope of the present invention.
Claims (2)
1. A configuration method of SQL sentences based on MyBatis, the method is executed by a configuration system of SQL sentences based on MyBatis, the system includes MyBatis frame, core configuration file, mapping configuration file and database, characterized in that: the core configuration file is an XML file for configuring global information and comprises a user name, a password and a link of a database and drive information selected by the database;
the MyBatis framework is used for operating the database, and the method comprises the following steps:
step A: introducing a MyBatis framework dependency library and a driver of the database into a java project;
and B: writing the core configuration file;
and C: creating the mapping configuration file, wherein the mapping configuration file transmits SQL sentences serving as parameters into the MyBatis framework, and the MyBatis framework judges the transmitted SQL sentences and judges the type of the SQL sentences;
if the type of the SQL statement as the parameter is the query type, returning a list, wherein each element on the list is a map object; if the type of the SQL statement as the parameter is a modification type, directly returning the number of the influenced records;
step D: and formulating SQL sentences through IDs according to the databases of different types, reading the configured SQL sentences and executing the sentences, and finally obtaining results.
2. The method of claim 1, wherein the method comprises the following steps:
the mapping configuration file is an XML file for configuring an ORM mapping relation and an SQL statement.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201711143542.4A CN108121542B (en) | 2017-11-17 | 2017-11-17 | MyBatis-based SQL statement configuration method and system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201711143542.4A CN108121542B (en) | 2017-11-17 | 2017-11-17 | MyBatis-based SQL statement configuration method and system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108121542A CN108121542A (en) | 2018-06-05 |
CN108121542B true CN108121542B (en) | 2021-07-06 |
Family
ID=62228476
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201711143542.4A Active CN108121542B (en) | 2017-11-17 | 2017-11-17 | MyBatis-based SQL statement configuration method and system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108121542B (en) |
Families Citing this family (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109933571B (en) * | 2019-01-23 | 2023-07-21 | 平安科技(深圳)有限公司 | Database design document generation method, device and computer readable storage medium |
CN110309365B (en) * | 2019-04-09 | 2023-07-25 | 长飞光纤光缆股份有限公司 | Openstack data query method and device based on Mybatis |
CN110765152B (en) * | 2019-09-18 | 2023-05-30 | 平安科技(深圳)有限公司 | SQL extraction method, SQL extraction device, computer equipment and storage medium |
CN110851346B (en) * | 2019-09-24 | 2024-05-31 | 平安科技(深圳)有限公司 | Query statement boundary problem detection method, device, equipment and storage medium |
CN110866029B (en) * | 2019-10-11 | 2022-08-09 | 支付宝(杭州)信息技术有限公司 | sql statement construction method, device, server and readable storage medium |
CN111158646A (en) * | 2019-12-17 | 2020-05-15 | 广西交通设计集团有限公司 | SQL lightweight persistent layer framework and configuration method |
CN111241064B (en) * | 2020-01-10 | 2023-11-03 | 深圳震有科技股份有限公司 | Database configuration file processing method, device and storage medium |
CN111949491B (en) * | 2020-08-14 | 2023-10-27 | 中国工商银行股份有限公司 | SQL extraction method and device of MyBatis application program |
CN113392122B (en) * | 2021-06-09 | 2022-03-11 | 北京同创永益科技发展有限公司 | Method for separating and operating HQL based on Mybatis framework |
CN114756554B (en) * | 2022-06-13 | 2022-09-30 | 中建电子商务有限责任公司 | Data query processing method based on MyBatis framework |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106020847A (en) * | 2016-06-06 | 2016-10-12 | 北京京东尚科信息技术有限公司 | Method and device for configuring SQL for persistent layer development framework |
CN106294075A (en) * | 2016-08-17 | 2017-01-04 | 浪潮软件股份有限公司 | A kind of SQL is monitored method, Apparatus and system |
CN106844678A (en) * | 2017-01-24 | 2017-06-13 | 山东浪潮商用系统有限公司 | A kind of exchange method of Mybatis data sources and connection pool |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8103644B2 (en) * | 2005-01-12 | 2012-01-24 | Microsoft Corporation | Data access layer class generator |
-
2017
- 2017-11-17 CN CN201711143542.4A patent/CN108121542B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106020847A (en) * | 2016-06-06 | 2016-10-12 | 北京京东尚科信息技术有限公司 | Method and device for configuring SQL for persistent layer development framework |
CN106294075A (en) * | 2016-08-17 | 2017-01-04 | 浪潮软件股份有限公司 | A kind of SQL is monitored method, Apparatus and system |
CN106844678A (en) * | 2017-01-24 | 2017-06-13 | 山东浪潮商用系统有限公司 | A kind of exchange method of Mybatis data sources and connection pool |
Also Published As
Publication number | Publication date |
---|---|
CN108121542A (en) | 2018-06-05 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108121542B (en) | MyBatis-based SQL statement configuration method and system | |
US8392880B2 (en) | Rapid application development for database-aware applications | |
CN104133772B (en) | Automatic test data generation method | |
US20040158820A1 (en) | System for generating an application framework and components | |
CN106598612B (en) | Operation method and system for data table in database | |
CN102117202B (en) | J2EE architecture-based code generating device | |
US20060048107A1 (en) | Enhanced compiled representation of transformation formats | |
CN101996131A (en) | Automatic test method and automatic test platform for graphic user interface (GUI) based on x extensive makeup language (XML) packaging key word | |
CN111078702B (en) | SQL sentence classification management and unified query method and device | |
US8417690B2 (en) | Automatically avoiding unconstrained cartesian product joins | |
CN108073688B (en) | Data migration method and device | |
CN108762743A (en) | Data table operation code generation method and device | |
CN103559025A (en) | Software refactoring method through clustering | |
CN108509199A (en) | Method, device, equipment and storage medium for automatically generating Chinese annotations | |
CN109710631A (en) | Auxiliary generates method, apparatus, equipment and the computer storage medium of SQL code | |
CN111061739A (en) | Method and device for warehousing massive medical data, electronic equipment and storage medium | |
CN103095726A (en) | Processing method and device of protocol interpreter | |
CN102253975A (en) | Automatic switching system and method for database | |
CN112162751A (en) | Automatic generation method and system of interface document | |
CN106599167A (en) | System and method capable of supporting incremental upgrading of database | |
CN104503767A (en) | System and method for automatically generating codes based on LIN protocol | |
CN114238527A (en) | Data processing method and data processing device based on object relation mapping | |
CN110334001A (en) | A kind of method and apparatus that batch automatically generates echo test | |
CN103593182A (en) | Method for reconfiguring software by using clustering mode | |
CN114064601B (en) | Storage process conversion method, device, equipment and storage medium |
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 |