A database query method and apparatus

By building a database repository layer and using MyBatis-Plus, the single-table query process is simplified, solving the problem of cumbersome query statements in existing technologies and improving query efficiency.

CN116467334BActive Publication Date: 2026-01-16PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310315640.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-28
Publication Date
2026-01-16
Estimated Expiration
2043-03-28

AI Technical Summary

Technical Problem

In existing technologies, when Java applications use MyBatis as a database access framework, single-table queries require writing query statements, resulting in a cumbersome and inefficient query process.

Method used

By building a database repository layer, the system obtains the identifier to be queried and uses the target queryer to query the data, simplifying the query process. It also utilizes MyBatis-Plus for secondary encapsulation, reducing reliance on XML configuration and improving development efficiency.

Benefits of technology

It enables fast single-table queries without the need to write query statements, simplifying the query process and improving the efficiency of single-table queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116467334B_ABST
    Figure CN116467334B_ABST
Patent Text Reader

Abstract

The application provides a database query method and device, the method comprises the following steps: constructing a warehouse layer of a database; obtaining a to-be-queried identifier; obtaining a target queryer corresponding to the to-be-queried identifier from the warehouse layer; and transmitting the to-be-queried identifier into the target queryer to perform data query, and obtaining a data query result. It can be seen that the single-table query can be quickly implemented, the query statement does not need to be written, and the query process is simple, so that the single-table query efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, in particular to a database query method and device. BACKGROUND

[0002] At present, when Java application uses MyBatis as a database layer access framework, there are many repeated codes in the database layer, and a certain template is presented, especially single table operation. For the query of some fields of single table, a SQL statement needs to be customized. It can be seen that in the existing method, the query statement needs to be written for single table query, the query process is cumbersome, and the single table query efficiency is low. SUMMARY

[0003] The purpose of the embodiments of the present application is to provide a database query method and device, which can quickly realize single table query, does not need to write query statement, and the query process is simple, thereby facilitating to improve the single table query efficiency.

[0004] The first aspect of the embodiments of the present application provides a database query method, comprising:

[0005] Constructing a warehouse layer of a database;

[0006] Obtaining a to-be-queried identifier;

[0007] Obtaining a target queryer corresponding to the to-be-queried identifier from the warehouse layer;

[0008] Transmitting the to-be-queried identifier into the target queryer for data query to obtain a data query result.

[0009] In the above implementation process, the method can preferentially construct a warehouse layer of a database; obtain a to-be-queried identifier; then obtain a target queryer corresponding to the to-be-queried identifier from the warehouse layer; and finally transmit the to-be-queried identifier into the target queryer for data query to obtain a data query result. It can be seen that the method can quickly realize single table query, does not need to write query statement, and the query process is simple, thereby facilitating to improve the single table query efficiency.

[0010] Further, the obtaining of the target queryer corresponding to the to-be-queried identifier from the warehouse layer comprises:

[0011] Determining a data transmission object according to the to-be-queried identifier;

[0012] Obtaining the target queryer from the warehouse layer according to the transmission object.

[0013] Further, the warehouse layer at least includes a single table adding code package, a single table deleting code package, a single table modifying code package, a DAO layer support component, a code generation component, a data access layer component, a logic generation component, a logic registry component, a dynamic query statement construction component, and a single table query builder construction component.

[0014] Further, the method further includes:

[0015] receiving a target single table added by the database;

[0016] generating, by the code generation component, single table processing code corresponding to the target single table;

[0017] configuring the single table processing code into the warehouse layer.

[0018] Further, the single table processing code includes a target single table adding code package, a target single table deleting code package, a target single table modifying code package, and a target single table query builder, the target single table adding code package is used for adding the target single table, the target single table deleting code package is used for deleting the target single table, the target single table modifying code package is used for modifying the target single table, and the target single table query builder is used for querying data of the target single table.

[0019] The second aspect of the embodiment of the present application provides a database query device, the database query device includes:

[0020] a construction unit, configured to construct a warehouse layer of a database;

[0021] a first acquisition unit, configured to acquire a to-be-queried identifier;

[0022] a second acquisition unit, configured to acquire, from the warehouse layer, a target query builder corresponding to the to-be-queried identifier;

[0023] a query unit, configured to transmit the to-be-queried identifier into the target query builder to query data, and obtain a data query result.

[0024] In the implementation process, the device can construct a warehouse layer of a database by the construction unit, acquire a to-be-queried identifier by the first acquisition unit, acquire, from the warehouse layer, a target query builder corresponding to the to-be-queried identifier by the second acquisition unit, and transmit the to-be-queried identifier into the target query builder to query data by the query unit, and obtain a data query result. It can be seen that the device can quickly implement single table query, does not need to write a query statement, and the query process is simple, thereby being beneficial to improving single table query efficiency.

[0025] Further, the second acquisition unit includes:

[0026] A determination sub-unit is configured to determine a data transmission object according to the to-be-queried identifier;

[0027] An acquisition sub-unit is configured to acquire a target queryer from the storage layer according to the transmission object.

[0028] Further, the storage layer at least includes a single-table addition code package, a single-table deletion code package, a single-table modification code package, a DAO layer support component, a code generation component, a data access layer component, a logic generation component, a logic registry component, a dynamic query statement construction component, and a single-table queryer construction component.

[0029] Further, the database query apparatus further includes:

[0030] A receiving unit is configured to receive a target single table added by a database;

[0031] A generation unit is configured to generate single-table processing code corresponding to the target single table by using the code generation component;

[0032] A configuration unit is configured to configure the single-table processing code into the storage layer.

[0033] Further, the single-table processing code includes a target single-table addition code package, a target single-table deletion code package, a target single-table modification code package, and a target single-table queryer, the target single-table addition code package is configured to perform addition processing on the target single table, the target single-table deletion code package is configured to perform deletion processing on the target single table, the target single-table modification code package is configured to perform modification processing on the target single table, and the target single-table queryer is configured to perform data query processing on the target single table.

[0034] The third aspect of the embodiments of the present application provides an electronic device, including a memory and a processor, the memory is used to store a computer program, and the processor runs the computer program to make the electronic device execute the database query method in any one of the first aspect of the embodiments of the present application.

[0035] The fourth aspect of the embodiments of the present application provides a computer readable storage medium, which stores computer program instructions, when the computer program instructions are read and run by a processor, the database query method in any one of the first aspect of the embodiments of the present application is executed. BRIEF DESCRIPTION OF DRAWINGS

[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiments of the present application will be briefly introduced as follows. It should be understood that the following drawings only show some of the embodiments of the present application, and therefore should not be regarded as a limitation on the scope, and for those of ordinary skill in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0037] Figure 1 A flowchart of a database query method provided by the embodiment of the present application is shown in the figure.

[0038] Figure 2 A flowchart of another database query method provided by the embodiment of the present application is shown in the figure.

[0039] Figure 3 A structural diagram of a database query device provided by the embodiment of the present application is shown in the figure.

[0040] Figure 4 A structural diagram of another database query device provided by the embodiment of the present application is shown in the figure.

[0041] Figure 5 A structural diagram of a warehouse layer design provided by the embodiment of the present application is shown in the figure. DETAILED DESCRIPTION

[0042] The technical solutions in the embodiments of the present application will be described in detail below with reference to the drawings in the embodiments of the present application.

[0043] It should be noted that: similar reference numerals and letters represent similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings. Meanwhile, in the description of the present application, the terms "first", "second", etc. are only used for distinguishing description, and cannot be understood as indicating or implying relative importance.

[0044] Embodiment 1

[0045] Please refer to Figure 1 , Figure 1 A flowchart of a database query method provided by the embodiment is shown in the figure. The database query method includes:

[0046] S101, constructing a warehouse layer of a database.

[0047] In the embodiment, the warehouse layer at least includes a single table addition code package, a single table deletion code package, a single table modification code package, a DAO layer support component, a code generation component, a data access layer component, a logic generation component, a logic registry component, a dynamic query statement construction component, and a single table query builder component.

[0048] S102, acquire the to-be-queried identifier.

[0049] S103, acquire the target queryer corresponding to the to-be-queried identifier from the warehouse layer.

[0050] S104, transmit the to-be-queried identifier into the target queryer for data query, and obtain a data query result.

[0051] In this embodiment, the execution subject of the method can be a computer, a server, or the like, and the embodiment is not limited in this regard.

[0052] In this embodiment, the execution subject of the method can also be a smart phone, a tablet computer, or the like, and the embodiment is not limited in this regard.

[0053] It can be seen that the database query method described in this embodiment can quickly implement single-table query, does not need to write a query statement, and has a simple query process, thereby facilitating improvement of single-table query efficiency.

[0054] Embodiment 2

[0055] Please refer to Figure 2 , Figure 2 A flowchart of a database query method is provided in this embodiment. The database query method includes the following steps.

[0056] S201, construct a warehouse layer of a database.

[0057] In this embodiment, the warehouse layer at least includes a single-table addition code package, a single-table deletion code package, a single-table modification code package, a DAO layer support component, a code generation component, a data access layer component, a logic generation component, a logic registry component, a dynamic query statement construction component, and a single-table queryer construction component.

[0058] S202, acquire the to-be-queried identifier.

[0059] S203, determine a data transmission object according to the to-be-queried identifier.

[0060] S204, acquire a target queryer from the warehouse layer according to the transmission object.

[0061] S205, transmit the to-be-queried identifier into the target queryer for data query, and obtain a data query result.

[0062] S206, receive a target single table added by the database.

[0063] S207, generate single-table processing code corresponding to the target single table by using the code generation component.

[0064] In this embodiment, the single table processing code includes a target single table addition code package, a target single table deletion code package, a target single table modification code package, and a target single table queryer. The target single table addition code package is used for adding a target single table, the target single table deletion code package is used for deleting a target single table, the target single table modification code package is used for modifying a target single table, and the target single table queryer is used for querying data of a target single table.

[0065] In S208, the single table processing code is configured into the warehouse layer.

[0066] In this embodiment, the method focuses on solving the problem of the current database query limitation. Specifically, the method extracts this part into a general warehouse design, thereby reducing the development work to a certain extent, so that the developer can focus more on business code development.

[0067] In this embodiment, the database warehouse layer design mainly relies on Mybatis+Mybatis Plus, and secondary encapsulation development is completed thereon; the original development work is simplified, and after using the tool, no meaningless code development needs to be performed for a single table, and a code example is as follows:

[0068] FormCounterPartyDTO formCounterPartyDTO=

[0069] Repository.of(FormCounterPartyDTO.class).getById(id).get();

[0070] As shown in the above code, it is expected to query the database according to the ID, only the corresponding queryer needs to be obtained from the warehouse layer according to the DTO, and then the ID is input to return the corresponding result. Compared with the traditional development process, the development efficiency is greatly improved.

[0071] In this embodiment, MyBatis is an excellent persistence layer framework, which supports customized SQL, stored procedures, and advanced mapping. MyBatis avoids almost all JDBC codes and manual parameter setting and result set acquisition. MyBatis can use simple XML or annotations to configure and map native information, and map interfaces and Java POJOs (Plain Ordinary Java Object, ordinary Java object) into records in a database.

[0072] In the embodiment, because Mybatis needs to write an XML configuration file, an XML file needs to be written to access the database, and all operations need to be completed through the XML. The CRUD of a single table also needs to use an XML file to complete. In this way, the requirements for the developer are increased, and the developer needs to be particularly familiar with the SQL language to complete the operation.

[0073] In the embodiment, MyBatis-Plus (MP for short) is an enhanced tool based on MyBatis. The basic functions of MyBatis are enhanced, but no changes are made. The developer can directly upgrade MyBatis to MyBatis-plus in the MyBatis development project. As it positions itself, it can help further simplify the development process and improve the development efficiency.

[0074] In the embodiment, Mybatis-Plus can be regarded as a re-encapsulation of Mybatis. After upgrading, the CRUD operation of a single table can be easily realized by calling the API provided by Mybatis-Plus. In addition, various query methods, paging, and other behaviors are provided. The developer does not need to write XML, which greatly reduces the development difficulty.

[0075] In the embodiment, the data transfer object (DTO) is a software application system for transmitting data between design patterns. The data transfer object is often retrieved from the database by the data access object.

[0076] In the embodiment, the warehouse layer class design can refer to Figure 5 as shown.

[0077] In the embodiment, the Repository is the only implementation for external, which provides common single table adding, deleting, modifying, and searching functions. The specific functions depend on the Provider, and the actual function logic is executed by delegation. The RepositoryFactory generates the Repository corresponding to each single table, and the RepositoryFactory delegates the Persistence to generate various specific logics for database operations.

[0078] In the embodiment, the Repository is the data access layer Repository code.

[0079] In the embodiment, the Provider is a data provider.

[0080] In the embodiment, the RepositoryFactory is a code generation component.

[0081] In the embodiment, Persistence is a persistence logic generation component, and persistence is a mechanism for converting program data between persistent state and transient state. Specifically, persistence, i.e., saving data (such as objects in memory) to a permanently saveable storage device (such as a disk). The main application of persistence is to store objects in memory in a database, or in a disk file, an XML data file, etc.

[0082] In the embodiment, the execution subject of the method can be a computer, a server, or the like computing device, and the embodiment does not make any limitation thereto.

[0083] In the embodiment, the execution subject of the method can also be a smart phone, a tablet computer, or the like smart device, and the embodiment does not make any limitation thereto.

[0084] It can be seen that the database query method described in the embodiment can quickly implement single-table query, does not need to write a query statement, and the query process is simple, thereby facilitating improvement of single-table query efficiency.

[0085] Embodiment 3

[0086] Please refer to Figure 3 , Figure 3 A structural schematic diagram of a database query device provided in the embodiment is shown in FIG. 3. As shown in the figure, the database query device includes: Figure 3

[0087] A construction unit 310, configured to construct a warehouse layer of a database;

[0088] A first acquisition unit 320, configured to acquire a to-be-queried identifier;

[0089] A second acquisition unit 330, configured to acquire, from the warehouse layer, a target queryer corresponding to the to-be-queried identifier;

[0090] A query unit 340, configured to input the to-be-queried identifier into the target queryer to perform data query, and obtain a data query result.

[0091] In the embodiment, the explanation and description of the database query device can refer to the description in Embodiment 1 or Embodiment 2, and the embodiment does not make any further description.

[0092] It can be seen that the database query device described in the embodiment can quickly implement single-table query, does not need to write a query statement, and the query process is simple, thereby facilitating improvement of single-table query efficiency.

[0093] Embodiment 4

[0094] Please refer to Figure 4 ,​Figure 4 A structural schematic diagram of a database query device is provided in the embodiment. As shown in the figure, the database query device comprises: Figure 4

[0095] A construction unit 310, configured to construct a warehouse layer of a database;

[0096] A first acquisition unit 320, configured to acquire a to-be-queried identifier;

[0097] A second acquisition unit 330, configured to acquire, from the warehouse layer, a target queryor corresponding to the to-be-queried identifier;

[0098] A query unit 340, configured to transmit the to-be-queried identifier into the target queryor for data query, to obtain a data query result.

[0099] As an optional implementation, the second acquisition unit 330 comprises:

[0100] A determination subunit 331, configured to determine a data transmission object according to the to-be-queried identifier;

[0101] An acquisition subunit 332, configured to acquire, from the warehouse layer, the target queryor according to the transmission object.

[0102] In the embodiment, the warehouse layer at least comprises a single-table addition code package, a single-table deletion code package, a single-table modification code package, a DAO layer support component, a code generation component, a data access layer component, a logic generation component, a logic registry component, a dynamic query statement construction component, and a single-table queryor construction component.

[0103] As an optional implementation, the database query device further comprises:

[0104] A receiving unit 350, configured to receive a target single table added by a database;

[0105] A generation unit 360, configured to generate, by a code generation component, single-table processing code corresponding to the target single table;

[0106] A configuration unit 370, configured to configure the single-table processing code into the warehouse layer.

[0107] In the embodiment, the single-table processing code comprises a target single-table addition code package, a target single-table deletion code package, a target single-table modification code package, and a target single-table queryor. The target single-table addition code package is configured to perform addition processing on the target single table, the target single-table deletion code package is configured to perform deletion processing on the target single table, the target single-table modification code package is configured to perform modification processing on the target single table, and the target single-table queryor is configured to perform data query processing on the target single table.

[0108] ​In this embodiment, the explanation of the database query device can refer to the description in Embodiment 1 or Embodiment 2, and the description in this embodiment will not be repeated.

[0109] It can be seen that the database query device described in this embodiment can quickly realize single table query, does not need to write query statements, and the query process is simple, thereby facilitating the improvement of single table query efficiency.

[0110] The electronic device provided in the embodiments of the present application includes a memory and a processor, the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the database query method in Embodiment 1 or Embodiment 2 of the present application.

[0111] The computer readable storage medium provided in the embodiments of the present application stores computer program instructions, and the computer program instructions are read and run by a processor to execute the database query method in Embodiment 1 or Embodiment 2 of the present application.

[0112] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are only schematic. For example, the flowcharts and block diagrams in the drawings show the possible implementation architectures, functions and operations of the devices, methods and computer program products according to the embodiments of the present application. In this regard, each block in the flowcharts or block diagrams can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur in different orders from those described in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and sometimes they can be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and the combination of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system for performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.

[0113] In addition, each functional module in the embodiments of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0114] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the parts of the prior art that make contributions or parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0115] The above merely provides an example of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that similar reference numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.

[0116] The above merely provides an example of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that similar reference numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.

[0117] It should be noted that, in this document, the terms such as first and second are used merely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the processes, methods, articles or devices including a series of elements not only include those elements, but also include other elements not explicitly listed or inherent to such processes, methods, articles or devices. Without more limitations, the element defined by the statement "including a" does not exclude the presence of another identical element in the process, method, article or device including the element.

Claims

1. A database query method, characterized by, The method comprises the following steps: constructing a warehouse layer of a database; obtaining a to-be-queried identifier; obtaining a target queryer corresponding to the to-be-queried identifier from the warehouse layer; transmitting the to-be-queried identifier into the target queryer for data query to obtain a data query result; wherein the step of obtaining the target queryer from the warehouse layer comprises the following steps: determining a data transmission object according to the to-be-queried identifier; obtaining the target queryer from the warehouse layer according to the transmission object. The warehouse layer comprises at least a single-table addition code package, a single-table deletion code package, a single-table modification code package, a DAO layer support component, a code generation component, a data access layer component, a logic generation component, a logic registry component, a dynamic query statement construction component, and a single-table queryer construction component.

2. The database query method of claim 1, wherein, The method further comprises the following steps: receiving a target single table added in the database; generating single-table processing code corresponding to the target single table by using the code generation component; configuring the single-table processing code into the warehouse layer.

3. The database query method of claim 2, wherein, The single-table processing code comprises a target single-table addition code package, a target single-table deletion code package, a target single-table modification code package, and a target single-table queryer, the target single-table addition code package is used for adding the target single table, the target single-table deletion code package is used for deleting the target single table, the target single-table modification code package is used for modifying the target single table, and the target single-table queryer is used for querying data of the target single table.

4. A database query apparatus, characterized by, The database query device comprises: a construction unit configured to construct a warehouse layer of a database; a first obtaining unit configured to obtain a to-be-queried identifier; a second obtaining unit configured to obtain a target queryer corresponding to the to-be-queried identifier from the warehouse layer; a query unit configured to transmit the to-be-queried identifier into the target queryer for data query to obtain a data query result. The second obtaining unit comprises: a determining subunit configured to determine a data transmission object according to the to-be-queried identifier; an obtaining subunit configured to obtain the target queryer from the warehouse layer according to the transmission object. The warehouse layer comprises at least a single-table addition code package, a single-table deletion code package, a single-table modification code package, a DAO layer support component, a code generation component, a data access layer component, a logic generation component, a logic registry component, a dynamic query statement construction component, and a single-table queryer construction component.

5. An electronic device, comprising: The electronic device comprises a memory and a processor, the memory is configured to store a computer program, and the processor is configured to run the computer program to enable the electronic device to execute the database query method in any one of claims 1 to 3.

6. A readable storage medium, characterized by, The readable storage medium stores computer program instructions, and the computer program instructions are read and run by a processor to execute the database query method in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Code generation method and device, storage medium and electronic device

    CN114253546A

  • Data processing method and storage medium

    CN114418514A