Nothing Special   »   [go: up one dir, main page]

CN114756554B - Data query processing method based on MyBatis framework - Google Patents

Data query processing method based on MyBatis framework Download PDF

Info

Publication number
CN114756554B
CN114756554B CN202210660674.9A CN202210660674A CN114756554B CN 114756554 B CN114756554 B CN 114756554B CN 202210660674 A CN202210660674 A CN 202210660674A CN 114756554 B CN114756554 B CN 114756554B
Authority
CN
China
Prior art keywords
xml file
mybatis
sql
name
database
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
Application number
CN202210660674.9A
Other languages
Chinese (zh)
Other versions
CN114756554A (en
Inventor
王德海
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China State Construction eCommerce Co Ltd
Original Assignee
China State Construction eCommerce Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China State Construction eCommerce Co Ltd filed Critical China State Construction eCommerce Co Ltd
Priority to CN202210660674.9A priority Critical patent/CN114756554B/en
Publication of CN114756554A publication Critical patent/CN114756554A/en
Application granted granted Critical
Publication of CN114756554B publication Critical patent/CN114756554B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a data query processing method based on a MyBatis framework, belonging to the technical field of data query processing, comprising the steps of adopting annotation information to mark database table information in the MyBatis framework, starting the MyBatis framework, and obtaining annotation information of an entity object; creating a corresponding xml file according to the annotation information and storing the xml file in the memory; analyzing a Mapper interface written in a database, generating SQL sentences corresponding to the Mapper interface, combining the SQL sentences and the xml files to generate new xml files and storing the new xml files in an internal memory; reading a new xml file to generate a corresponding Java object; reading the Java object, and analyzing a corresponding SQL statement; executing the analyzed SQL sentence to perform database operation and generate an execution result; and returning the execution result to the user. The invention simplifies the operation of the single table, reduces the code amount and obviously enhances the code readability.

Description

Data query processing method based on MyBatis framework
Technical Field
The invention belongs to the technical field of data query processing, and particularly relates to a data query processing method based on a MyBatis framework.
Background
The software development industry generally uses Java as the server-side language, and most applications require permanent storage of data using a database as the storage medium. The data operations in the database are divided into 4 types, namely adding, modifying, deleting and inquiring. One of the ways of interaction between the Java language and the database is to use the MyBatis framework to add, modify, delete and query data. The MyBatis framework has a wide application range, most Internet companies use the MyBatis framework, the MyBatis framework is increasingly dependent on the MyBatis framework, and the MyBatis framework is convenient to use, high in performance and strong in flexibility. For a real-time system, the query operations of the database are more frequent than the addition, modification and deletion operations, and one type of the query operations is the most frequent, namely, the query operations are single-table query, namely, only one table is queried at a time. Because the structure of the single table is fixed and simple, if the code amount is too large, at least 4 lines of codes need to be written for simple query operation; the readability of the code is poor, and due to the large code amount, the time required for a user to read is long, and the time required for understanding is longer; the operation of the same function cannot be reused, so that the query of the MyBatis framework appears to be too troublesome.
Therefore, the invention provides a data query processing method based on a MyBatis framework, which simplifies the configuration and operation of a single table, reduces the code amount, improves the code readability and the code reuse, and becomes a technical problem to be solved by technical personnel in the technical field.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: a data query processing method based on a MyBatis framework is provided, and the technical problem that the existing single-table query is complicated is solved.
In order to realize the purpose, the technical scheme adopted by the invention is as follows:
a data query processing method based on a MyBatis framework comprises the following steps:
step S1, marking database table information by adopting annotation information in the MyBatis framework, starting the MyBatis framework, and obtaining the annotation information of the entity object;
step S2, creating a corresponding xml file according to the annotation information and storing the xml file in a memory;
step S3, analyzing the Mapper interface written in the database, generating SQL sentences corresponding to the Mapper interface, combining the SQL sentences and the xml file to generate a new xml file and storing the new xml file in the memory;
step S4, reading a new xml file to generate a corresponding Java object;
step S5, reading the Java object, and analyzing the corresponding SQL sentence;
step S6, executing the analyzed SQL sentence to perform database operation and generate an execution result;
and step S7, returning the execution result to the user.
Further, in step S1, the annotation information is subjected to the configuration of the entity class and the configuration of the xml file.
Further, in step S1, the database table information includes a database table name, a primary key, and a database column name.
Further, step S3 specifically includes: step S31, determining search basis characters, compiling a Mapper interface method name with the determined search basis characters, taking entity attribute hump names as attribute query conditions, and adding an operation mode at the end of attributes; step S32, connecting the attributes by adopting logical operation, and combining to obtain a plurality of query conditions; step S33, the query conditions correspond to the method name parameters one by one; s34, analyzing the method name to generate a standard SQL statement when MyBatis executes, S35, merging the SQL statement and the corresponding xml file to generate a new xml file; and step S36, storing the new xml file in the memory.
Furthermore, a plurality of attributes are connected by using a logical operation And Or.
Further, in step S3, the method name parameter corresponds to a database field.
Further, in step S5, all information in the Java object is obtained, where all information includes the SQL statement, the operation type, the parameter information, and the return value information, and the SQL statement is obtained and executed.
Compared with the prior art, the invention has the following beneficial effects:
the invention has scientific and reasonable design and convenient use, and solves the technical problem of complicated query of the existing single table. The method comprises the steps of creating and merging the xml files, reading and analyzing the SQL sentences of the xml files, executing the SQL sentences and returning the execution results. The invention is based on MyBatis, simplifies the operation of the single table, obviously reduces the code amount, and obviously enhances the readability of the code.
Drawings
FIG. 1 is a flow chart of the method of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to the accompanying drawings. It is to be understood that the described embodiments are merely exemplary of the invention, and not restrictive of the full scope of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The invention explains and explains the following technical names:
MyBatis framework: a java based persistence tier framework;
an xml file: a markup language for marking electronic documents to be structured;
SQL statement: a structured query language.
As shown in FIG. 1, the data query processing method based on the MyBatis framework provided by the invention has scientific and reasonable design and convenient use, and solves the technical problem of complicated query of the existing single table. The method comprises the steps of creating and merging the xml files, reading and analyzing the SQL sentences of the xml files, executing the SQL sentences and returning the execution results. The invention is based on MyBatis, simplifies the operation of the single table, obviously reduces the code amount, and obviously enhances the readability of the code.
The invention comprises the following steps:
step S1, marking database table information by adopting annotation information in the MyBatis framework, starting the MyBatis framework, and obtaining the annotation information of the entity object;
step S2, creating a corresponding xml file according to the annotation information and storing the xml file in a memory;
step S3, analyzing the Mapper interface written in the database, generating SQL sentences corresponding to the Mapper interface, combining the SQL sentences and the xml file to generate a new xml file and storing the new xml file in the memory;
step S4, reading a new xml file to generate a corresponding Java object;
step S5, reading the Java object, and analyzing the corresponding SQL sentence;
step S6, executing the analyzed SQL sentence to perform database operation and generate an execution result;
and step S7, returning the execution result to the user.
The MyBatis framework is optimized based on the MyBatis framework, so that the single-table operation can be simplified, the user does not need to compile an xml file, and the xml file can be automatically generated; the user does not need to write multiple lines of dynamic query codes, only needs to analyze the operation semantics, writes a corresponding Mapper method, and automatically analyzes the name of the Mapper method to generate SQL sentences corresponding to the xml file. For example, the existing requirements: the size of a query field version field is 2-4, single-table query is carried out by using other common frames and the optimized MyBatis frame according to id reverse sequencing, query results are the same, but the code amount is less and the readability is better.
In step S1, the present invention performs entity class configuration and xml file configuration on the annotation information, and in particular, the entity class configuration and xml file configuration may or may not be operable, and do not affect the subsequent steps. The database table information comprises a database table name, a primary key and a database column name.
Step S3 of the present invention specifically includes: step S31, determining a search basis character (findBy), writing a Mapper interface method Name at the beginning of the determined search basis character findBy, taking an entity attribute hump Name (hump Name word initials need to be written in large (such as Name, Password, Usernfo And the like) as an attribute query condition, And adding an operation mode (such as Namelike, Passsword LT, UsernfoNull And the like) at the end of the attribute, step S32, connecting a plurality of attributes by adopting a logical operation, combining to obtain a plurality of query conditions, particularly, using an Or an connection (such as NameLikeAndPassWordBatLlt; after the initial search basis character is added, finnPasesword is added), step S33, corresponding the query condition And the method Name parameter to each other (such as NamePasesPasesPasesPasesword) And generating a Mapper interface method Name # 36, such as MyerdPasesdPasesx # analysis statement), combining the SQL sentences with the corresponding xml files to generate new xml files; and step S36, storing the new xml file in the memory. Specifically, each database column in the database table of the database corresponds to a database field, and the database field corresponds to the method name parameter.
The first step, reading a MyBatis configuration file, analyzing the configuration file, and generating a relevant Java object; reading various mapper. xml files, and generating SQL statements corresponding to the interface method and related parameters, operation types, return values and other information; thirdly, executing the mapper interface method, acquiring SQL sentences and related information from related Java objects, and executing; and fourthly, returning an execution result. Annotation information is adopted in the MyBatis framework flow to mark information such as database table names, main keys, database column names and the like; in the second step above, the logic of the present application enhances the MyBatis framework; the enhanced place is that the method of beginning with find is analyzed to generate the corresponding SQL statement and the related information of parameters, operation types, return values and the like, and the SQL statement and the related information are merged with the MyBatis native object.
In step S5, all information in the Java object is obtained, including the SQL statement, the operation type, the parameter information, and the return value information, and the SQL statement is obtained and executed.
Finally, it should be noted that: the above embodiments are only preferred embodiments of the present invention to illustrate the technical solutions of the present invention, but not to limit the technical solutions, and certainly not to limit the scope of the present invention; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention; that is, the technical problems to be solved by the present invention, which are not substantially changed or supplemented by the spirit and the concept of the main body of the present invention, are still consistent with the present invention and shall be included in the scope of the present invention; in addition, the technical scheme of the invention is directly or indirectly applied to other related technical fields, and the technical scheme is included in the patent protection scope of the invention.

Claims (6)

1. A data query processing method based on a MyBatis framework is characterized by comprising the following steps:
step S1, marking database table information by adopting annotation information in the MyBatis framework, starting the MyBatis framework, and obtaining the annotation information of the entity object;
step S2, creating a corresponding xml file according to the annotation information and storing the xml file in a memory;
step S3, analyzing the Mapper interface written in the database, generating SQL sentences corresponding to the Mapper interface, combining the SQL sentences and the xml file to generate a new xml file and storing the new xml file in the memory;
step S4, reading the new xml file to generate a corresponding Java object;
step S5, reading the Java object, and analyzing the corresponding SQL sentence;
step S6, executing the analyzed SQL sentence to perform database operation and generate an execution result;
step S7, returning the execution result to the user;
step S3 specifically includes: step S31, determining a finding basis character findBy, writing a Mapper interface method name by taking the determined finding basis character findBy as the beginning, taking an entity attribute hump name as an attribute query condition, and adding an operation mode corresponding to each attribute at the tail of each attribute; step S32, connecting the attributes by adopting logical operation, and combining to obtain a plurality of query conditions; s33, enabling the query conditions obtained by the combination in the S32 to correspond to the name parameters of the method of the Mapper interface one by one, and compiling the name of the method of the Mapper interface based on the processes of the S31-S33; step S34, analyzing the name of the Mapper interface method to generate a standard SQL statement when MyBatis executes; step S35, merging the SQL statement and the corresponding xml file to generate a new xml file; and step S36, storing the new xml file in the memory.
2. The data query processing method based on MyBatis framework as claimed in claim 1, wherein in step S1, the configuration of entity class and the configuration of xml file are performed on the annotation information.
3. The MyBatis framework-based data query processing method according to claim 1, wherein in step S1, the database table information includes database table name, primary key and database column name.
4. The MyBatis framework-based data query processing method of claim 1, wherein logical operations And Or connection is adopted between a plurality of attributes.
5. The MyBatis framework-based data query processing method of claim 1, wherein in step S3, the Mapper interface method name parameter corresponds to a database field.
6. The MyBatis framework-based data query processing method according to claim 1, wherein in step S5, all information in a Java object is obtained, the all information includes SQL statements, operation types, parameter information, and return value information, and the SQL statements are obtained and executed.
CN202210660674.9A 2022-06-13 2022-06-13 Data query processing method based on MyBatis framework Active CN114756554B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210660674.9A CN114756554B (en) 2022-06-13 2022-06-13 Data query processing method based on MyBatis framework

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210660674.9A CN114756554B (en) 2022-06-13 2022-06-13 Data query processing method based on MyBatis framework

Publications (2)

Publication Number Publication Date
CN114756554A CN114756554A (en) 2022-07-15
CN114756554B true CN114756554B (en) 2022-09-30

Family

ID=82336931

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210660674.9A Active CN114756554B (en) 2022-06-13 2022-06-13 Data query processing method based on MyBatis framework

Country Status (1)

Country Link
CN (1) CN114756554B (en)

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105487864A (en) * 2015-11-26 2016-04-13 北京京东尚科信息技术有限公司 Method and device for automatically generating code
CN107479883A (en) * 2017-08-07 2017-12-15 海闻科技有限公司 A kind of code generating method and code generator
CN108121542A (en) * 2017-11-17 2018-06-05 广东睿江云计算股份有限公司 A kind of collocation method of the SQL statement based on MyBatis, system
CN110046170A (en) * 2019-04-22 2019-07-23 深圳乐信软件技术有限公司 Sentence based on multifile management executes method, apparatus, equipment and medium
CN111125440A (en) * 2019-12-09 2020-05-08 重庆邮电大学 Monad-based persistent layer composite condition query method and storage medium
CN111488143A (en) * 2020-04-15 2020-08-04 南京及物智能技术有限公司 Automatic code generation device and method based on Springboot2
CN111782195A (en) * 2020-06-30 2020-10-16 广州云徙科技有限公司 Query method based on adding annotation on request parameter and splicing into SQL
CN111949491A (en) * 2020-08-14 2020-11-17 中国工商银行股份有限公司 SQL extraction method and device for MyBatis application program
CN112905636A (en) * 2021-03-31 2021-06-04 浙江太美医疗科技股份有限公司 Data manipulation method, server, and computer-readable medium
CN112905453A (en) * 2021-02-03 2021-06-04 重庆富民银行股份有限公司 Method for quickly generating database operation code in automatic test
CN114238527A (en) * 2022-02-24 2022-03-25 安翰科技(武汉)股份有限公司 Data processing method and data processing device based on object relation mapping

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7310637B2 (en) * 2004-05-05 2007-12-18 International Business Machines Corporation Dynamic database access via standard query language and abstraction technology
CN106775770B (en) * 2017-01-16 2020-08-11 兴唐通信科技有限公司 Search method for constructing query statement based on class information
US20210224900A1 (en) * 2018-02-09 2021-07-22 Deutsche Ag Stress testing and entity planning model execution apparatus, method, and computer readable media
CN109471619A (en) * 2018-11-20 2019-03-15 北京千丁互联科技有限公司 Mybatis code generating method, device and terminal
WO2020232569A1 (en) * 2019-05-17 2020-11-26 环球雅途集团有限公司 Database access layer representation method and device
CN112783915A (en) * 2019-11-04 2021-05-11 航天科工惯性技术有限公司 Data transmission object mapping method and unit based on SpringMVC + Mybatis framework
CN112306463B (en) * 2020-10-14 2024-02-20 深圳市中农网有限公司 Mybatis generation method, system, storage medium and device based on POJO
CN112307068A (en) * 2020-11-10 2021-02-02 天元大数据信用管理有限公司 Dynamic SQL query method
CN113704575B (en) * 2021-08-30 2023-07-14 上海一谈网络科技有限公司 SQL method, device, equipment and storage medium for analyzing XML and Java files

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105487864A (en) * 2015-11-26 2016-04-13 北京京东尚科信息技术有限公司 Method and device for automatically generating code
CN107479883A (en) * 2017-08-07 2017-12-15 海闻科技有限公司 A kind of code generating method and code generator
CN108121542A (en) * 2017-11-17 2018-06-05 广东睿江云计算股份有限公司 A kind of collocation method of the SQL statement based on MyBatis, system
CN110046170A (en) * 2019-04-22 2019-07-23 深圳乐信软件技术有限公司 Sentence based on multifile management executes method, apparatus, equipment and medium
CN111125440A (en) * 2019-12-09 2020-05-08 重庆邮电大学 Monad-based persistent layer composite condition query method and storage medium
CN111488143A (en) * 2020-04-15 2020-08-04 南京及物智能技术有限公司 Automatic code generation device and method based on Springboot2
CN111782195A (en) * 2020-06-30 2020-10-16 广州云徙科技有限公司 Query method based on adding annotation on request parameter and splicing into SQL
CN111949491A (en) * 2020-08-14 2020-11-17 中国工商银行股份有限公司 SQL extraction method and device for MyBatis application program
CN112905453A (en) * 2021-02-03 2021-06-04 重庆富民银行股份有限公司 Method for quickly generating database operation code in automatic test
CN112905636A (en) * 2021-03-31 2021-06-04 浙江太美医疗科技股份有限公司 Data manipulation method, server, and computer-readable medium
CN114238527A (en) * 2022-02-24 2022-03-25 安翰科技(武汉)股份有限公司 Data processing method and data processing device based on object relation mapping

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
一种基于源码分析和代码生成的ORM开发工具――EasyPersist;瞿华;《电脑知识与技术》;20160731(第20期);第89-92页 *

Also Published As

Publication number Publication date
CN114756554A (en) 2022-07-15

Similar Documents

Publication Publication Date Title
US7617444B2 (en) File formats, methods, and computer program products for representing workbooks
US6349305B1 (en) Method and system for database processing by invoking a function related to index type definition, generating an execution plan based on index type name
US6282539B1 (en) Method and system for database publishing
US7240340B2 (en) System and method for browse information parsing without compilation
CN101777045A (en) Method for analyzing XML file by indexing
CN112667563A (en) Document management and operation method and system
CN110955714A (en) Method and device for converting unstructured text into structured text
CN100338605C (en) Recording method for extendable mark language file repairing trace
US7111284B2 (en) System and method for mapping structured document to structured data of program language and program for executing its method
CN109542418B (en) Service code generation method and computer terminal
CN113703777B (en) Code generation method, device, storage medium and equipment based on database table
CN114756554B (en) Data query processing method based on MyBatis framework
CN112783927A (en) Database query method and system
CN112799638B (en) Non-invasive rapid development method, platform, terminal and storage medium
CN111325007B (en) Comment analysis method and terminal for PPTX file
CN114895875A (en) Zero-code visual information system metadata production application method and system
CN112346723A (en) Database access low-code generation middleware system
CN117193781B (en) SIMSCRIPT language-oriented abstract syntax tree construction method and device
CN118210809B (en) Object definition method, system, equipment and medium based on ER information
CN117193782B (en) Grammar mapping method and device from SIMSCRIPT language to C language
CN116627390B (en) ICD file substitution method and device in aviation software development
CN117850754A (en) Method and system for processing and executing expression of low-code support multi-platform
CN117331963B (en) Data access processing method and device, electronic equipment and storage medium
CN114385664A (en) Splitting method, system, device and storage medium for single project micro-service
JPH0736737A (en) Method for generating test data

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
EE01 Entry into force of recordation of patent licensing contract
EE01 Entry into force of recordation of patent licensing contract

Application publication date: 20220715

Assignee: Yunzhu Information Technology (Chengdu) Co.,Ltd.

Assignor: China Construction e-commerce Co.,Ltd.

Contract record no.: X2023980032450

Denomination of invention: A Data Query Processing Method Based on MyBatis Framework

Granted publication date: 20220930

License type: Common License

Record date: 20230220