Data query method and system, electronic equipment and storage medium
By intercepting query statements in the mybatis interceptor and automatically adding default restrictions, the poor scalability and memory overflow problems caused by manual addition of restrictions in the prior art are solved, and the security and scalability of query statements are achieved.
Patent Information
- Application Number
- CN202411632150.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-15
- Publication Date
- 2025-03-11
AI Technical Summary
In the prior art, the query statement is added by manual hard coding, resulting in poor scalability, easy to miss, and easy to find out a large amount of data, resulting in memory overflow.
By intercepting the query statement in the mybatis interceptor, determine whether there are corresponding identifiers and restrictions. If not, obtain the pre-configured default restrictions and configure them for the query statement, and generate a target query statement to avoid memory overflow.
It solves the omissions and scalability problems when manually adding restrictions, ensures the security and scalability of query statements, and avoids the risk of memory overflow.
Smart Images

Figure CN119597788A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more specifically, to a data query method, system, electronic device and storage medium. Background Art
[0002] With the continuous development of informatization, the speed of data generation is increasing, and the amount of data that needs to be processed is rapidly expanding. In order to improve the efficiency of data processing, the required data can be queried from a large amount of data through data query, so as to use the queried data for corresponding data processing.
[0003] In the existing data query method, corresponding restriction conditions can be added to the query statement by manual hard coding; however, this adding method is not only cumbersome, and manually adding corresponding restriction conditions for each query statement not only has poor scalability, but is also prone to omissions; at the same time, using this method to add restriction conditions to query statements for data query, it is also easy to find a large amount of data and cause memory overflow. Summary of the invention
[0004] In view of this, the present application provides a data query method, system, electronic device and storage medium to solve the problems in the prior art of adding restriction conditions to query statements by manual hard coding, resulting in poor scalability, easy omissions, and easy detection of large amounts of data leading to memory overflow.
[0005] The first aspect of the present application provides a data query method, which is applied to a pre-configured mybatis interceptor, including:
[0006] When a query statement is detected, intercepting the query statement;
[0007] Determine whether there is a corresponding identifier for the query statement;
[0008] If there is no corresponding identifier in the query statement, determine whether the query statement meets the data query condition;
[0009] If the query statement does not satisfy the data query condition, obtain a pre-configured default restriction condition, configure the default restriction condition for the query statement, and generate a target query statement;
[0010] The target query statement is used to query corresponding data from the database.
[0011] Optionally, determining whether the query statement satisfies a data query condition includes:
[0012] Determining whether there is a restriction condition in the query statement and whether the query statement type of the query statement is a preset query statement type;
[0013] If the query statement does not have a restriction condition, and the query statement type of the query statement is not the preset query statement type, determining that the query statement does not meet the data query condition;
[0014] If the query statement has restriction conditions, and / or the query statement type of the query statement is the preset query statement type, it is determined that the query statement meets the data query condition, and the query statement is used to query corresponding data from the database.
[0015] Optionally, the method further includes:
[0016] Determine whether the query statement has a custom annotation;
[0017] If the query statement has a custom annotation, generate an identifier and a key of the query statement according to the custom annotation of the query statement, and establish an association relationship between the identifier of the query statement and the key of the query statement;
[0018] The identifier of the query statement is stored in a preset thread context.
[0019] Optionally, determining whether the query statement has an identifier includes:
[0020] Get the Key corresponding to the query statement;
[0021] Determine whether there is an identifier matching the Key of the query statement in the context of the thread;
[0022] If there is an identifier matching the Key of the query statement in the context of the thread, determining that the query statement has a corresponding identifier;
[0023] If there is no identifier matching the Key of the query statement in the context of the thread, it is determined that there is no corresponding identifier for the query statement.
[0024] Optionally, determining whether there is an identifier matching the Key of the query statement in the context of the thread includes:
[0025] Determine whether there is an identifier associated with the Key of the query statement in the context of the thread;
[0026] If there is an identifier associated with the Key of the query statement in the context of the thread, determining that there is an identifier matching the Key in the context of the thread;
[0027] If there is no identifier associated with the Key of the query statement in the context of the thread, it is determined that there is no identifier matching the Key in the context of the thread.
[0028] Optionally, the method further includes:
[0029] If the query statement has a corresponding identifier, clear the identifier corresponding to the query statement in the online context according to the key of the query statement;
[0030] The corresponding data is queried from the database according to the query statement.
[0031] Optionally, if the query statement has a corresponding identifier, clearing the identifier corresponding to the query statement in the online context according to the key of the query statement includes:
[0032] If the query statement has a corresponding identifier, obtain the Key of the query statement, and determine the identifier associated with the Key of the query statement from the online context;
[0033] The identifier associated with the Key of the query statement in the context on the line is cleared.
[0034] The second aspect of the present application provides a data query system, which is applied to a pre-configured mybatis interceptor, and the system includes:
[0035] An interception unit, configured to intercept a query statement when a query statement is detected;
[0036] A first judgment unit, used to judge whether the query statement has a corresponding identifier;
[0037] A second judgment unit, configured to judge whether the query statement satisfies a data query condition if no corresponding identifier exists in the query statement;
[0038] A restriction condition configuration unit, configured to obtain a pre-configured default restriction condition if the query statement does not satisfy the data query condition, and configure the default restriction condition for the query statement to generate a target query statement;
[0039] The first data query unit is used to query corresponding data from the database using the target query statement.
[0040] The third aspect of the present application provides an electronic device, comprising: a processor and a memory, wherein the processor and the memory are connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; and the memory is used to store a program, wherein the program is used to implement the data query method provided in the first aspect of the present application.
[0041] A fourth aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to execute the data query method provided in the first aspect of the present application.
[0042] The present application provides a data query method, system, electronic device and storage medium, which are applied to a pre-configured mybatis interceptor. When a query statement is detected, the query statement is intercepted, and it is determined whether the query statement has a corresponding identifier; if there is no corresponding identifier in the query statement, it is determined whether the query statement meets the data query condition; if the query statement does not meet the data query condition, the pre-configured default restriction condition is obtained, and the default restriction condition is configured for the query statement to generate a target query statement; the target query statement is used to query the corresponding data from the database. The technical solution provided by the present application can intercept the query statement through the mybatis interceptor before using the query statement to query the database, that is, each time the query statement is detected to exist, the query statement is intercepted, and the omission of the restriction condition is solved by adding the restriction condition manually hard-coded in the prior art; after intercepting the query statement, if it is determined that the query statement does not have an identifier and does not meet the data query condition, it means that there is no corresponding restriction condition on the query statement, and the pre-configured default restriction condition can be automatically added to the query statement at this time, and the corresponding restriction condition can be added without manual hard coding, which ensures the scalability and security of the query statement, and can also prevent the query of a large amount of data from causing memory overflow. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0044] Figure 1 A flowchart of a data query method provided in an embodiment of the present application;
[0045] Figure 2 An example diagram of a data query method provided in an embodiment of the present application;
[0046] Figure 3 A structural example diagram of a data query system provided by an embodiment of the present invention;
[0047] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0048] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] In this application, relational terms such as first and second, etc. are used only 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 "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0050] From the above background technology, it can be seen that the current data query method is generally to manually add corresponding restrictions in each assembled query statement. However, due to the different coding capabilities of each user, there are scenarios where individuals manually add restrictions that are not well considered, that is, the scalability is poor and it is easy to miss, and there is no guarantee that the query statement after adding the restrictions is safe.
[0051] Therefore, the present application provides a data query method, that is, a method for adding restriction conditions to query statements based on a mybatis interceptor, by writing a corresponding mybatis interceptor based on the ORM framework (mybatis) extension mechanism and writing multiple classes based on the Interceptor plug-in of the mybatis interceptor; the written multiple classes are encapsulated into an SDK, and the SDK is configured into the plugins of the mybatis interceptor to obtain the mybatis interceptor pre-configured by the present application, so that in the mybatis execution, the pre-configured mybatis interceptor can be used to call the configured SDK to execute the data query method provided by the present application, so as to realize automatic addition of corresponding restriction conditions to the query statement in a non-invasive manner, without the need to manually add restriction conditions to each query statement, thereby avoiding omissions, and ensuring the security and scalability of the query statement after adding the restriction conditions, while also improving the efficiency of adding restriction conditions to the query statement.
[0052] See also Figure 1 , shows a flow chart of a data query method provided in an embodiment of the present application, the data query method is applied to a pre-configured mybatis interceptor, and the data query method specifically includes the following steps:
[0053] S101: When a query statement is detected, the query statement is intercepted and it is determined whether there is a corresponding identifier for the query statement. If there is no corresponding identifier for the query statement, step S102 is executed.
[0054] In the process of specifically executing step S101, the SDK configured on the corresponding mybatis interceptor written based on the ORM framework (mybatis) extension mechanism can be used to detect in real time whether there is a query statement at present; when the SDK configured on the mybatis interceptor detects that there is a query statement at present, the query statement is intercepted to determine whether it is necessary to add corresponding restrictions to the query statement, thereby avoiding omissions caused by adding restrictions by manual hard coding and the inability to ensure the security and scalability of the query statement. At the same time, it can also effectively prevent the situation where memory overflow occurs when the query statement is directly used to query the corresponding data.
[0055] In the embodiment of the present application, after the SDK configured on the mybatis interceptor intercepts the query statement, it can first determine whether the query statement has a special identifier; if there is a special identifier, it means that there is a corresponding custom annotation on the query statement, and the query statement can be directly used to query the corresponding data from the database without adding restriction conditions to the query statement, and the situation where a large amount of data is queried and memory overflows can also be avoided. If there is no special identifier, in order to avoid the situation where a large amount of data is queried and memory overflows, it can be further determined whether the query statement meets the data query condition, that is, step S102 is executed.
[0056] It should be noted that the identifier of the query statement is generated using the custom annotation of the query statement.
[0057] Optionally, the process of generating the identifier of the query statement may specifically include: determining whether the query statement has a custom annotation; if the query statement has a custom annotation, generating the identifier and key of the query statement according to the custom annotation of the query statement, and establishing an association relationship between the identifier of the query statement and the key of the query statement; storing the identifier of the query statement in the context of a pre-set thread.
[0058] In actual application, after intercepting a query statement, the mybatis interceptor can determine whether there is a corresponding custom annotation on the query statement; if there is a corresponding custom annotation on the query statement, the identifier and key of the query statement are generated according to the custom annotation of the query statement, and an association relationship between the identifier of the query statement and the key of the query statement is established; the spring interceptor is called to set the identifier of the query statement in the context of a pre-set thread, so as to achieve non-invasive transparent transmission of the parameters (custom annotations) corresponding to the query statement, so that during the execution of the mybatis interceptor, it can first be determined whether there is an identifier for the query statement. If it is determined that the query statement has an identifier, the identifier of the query statement can be cleared from the context of the thread according to the key of the query statement, and then the corresponding data can be obtained from the database according to the custom annotation in the query statement; if it is determined that the query statement does not have an identifier, step S102 can be executed. Among them, the custom annotation of the query statement includes corresponding annotation information, and the annotation information includes corresponding parameter information. The parameter information can limit the data to 5,000, that is, limit the queried data to 5,000. The custom annotation of the query statement can be set according to the actual application, and this embodiment of the present application is not limited here.
[0059] In some embodiments, the process of clearing the identifier corresponding to the query statement in the online context according to the Key of the query statement can be specifically as follows: the Key of the query statement can be obtained, and the identifier that is associated with the Key of the query statement can be determined from the online context, and finally the identifier that is associated with the Key of the query statement in the online context can be cleared.
[0060] It should be noted that the context of a thread is a storage medium of the thread, that is, after the identifier corresponding to the query statement is generated, the identifier of the query statement can be stored in the storage medium of the thread.
[0061] Optionally, after the mybatis interceptor intercepts the corresponding query statement, the process of determining whether the query statement has an identifier can be specifically: obtaining the key corresponding to the query statement; determining whether there is an identifier matching the key of the query statement in the context of the thread; if there is an identifier matching the key of the query statement in the context of the thread, determining that the query statement has a corresponding identifier; if there is no identifier matching the key of the query statement in the context of the thread, determining that the query statement does not have a corresponding identifier.
[0062] As a preferred method of an embodiment of the present application, the process of determining whether there is an identifier matching the Key of the query statement in the context of the thread may specifically be: determining whether there is an identifier associated with the Key of the query statement in the context of the thread; if there is an identifier associated with the Key of the query statement in the context of the thread, determining that there is an identifier matching the Key in the context of the thread; if there is no identifier associated with the Key of the query statement in the context of the thread, determining that there is no identifier matching the Key in the context of the thread.
[0063] It should be noted that, since there is a certain correlation between the Key of the query statement and the identifier of the query statement, after intercepting the corresponding query statement, the mybatis interceptor can first obtain the Key of the query statement to determine whether there is an identifier associated with the Key of the query statement in the context of the thread; if there is, it can be determined that the query statement has a corresponding identifier, and the identifier associated with the Key of the query statement in the context of the thread is cleared, and the corresponding data is queried from the database according to the parameter information in the custom annotation in the query statement. If not, it can be determined that the query statement does not have a corresponding identifier, and then step S102 can be executed.
[0064] S102: Determine whether the query statement meets the data query condition. If the query statement does not meet the data query condition, execute step S103.
[0065] In the process of specifically executing step S102, corresponding data query conditions can be set in advance so as to determine whether the query statement meets the data query conditions based on the query statement and its query statement type. If so, it means that the query statement does not need to add corresponding restriction conditions, and the query statement can be directly used to query the database to obtain corresponding data from the database; if not, it means that the query statement needs to add corresponding restriction conditions, and then step S103 can be executed to add corresponding restriction conditions to the query statement.
[0066] It should be noted that the limit condition may be a data limit of limit 5000, a data limit of limit 10000, etc., which may be set according to actual applications and is not limited in this embodiment of the present application.
[0067] In an embodiment of the present application, the data query condition indicates that there are corresponding restriction conditions in the query statement, or the query statement type of the query statement is a preset query statement type; accordingly, the process of determining whether the query statement satisfies the data query condition may specifically be: determining whether there are restriction conditions in the query statement, and whether the query statement type of the query statement is a preset query statement type; if there are no restriction conditions in the query statement, and the query statement type of the query statement is not a preset query statement type, determining that the query statement does not satisfy the data query condition; if there are restriction conditions in the query statement, and / or the query statement type of the query statement is a preset query statement type, determining that the query statement satisfies the data query condition, and using the query statement to query the corresponding data from the database.
[0068] It should be noted that the preset query statement type may be a statistical type, and the corresponding preset query statement type may be set according to actual applications, which is not limited in the embodiments of the present application.
[0069] It can be seen that, when the mybatis interceptor determines that there is no corresponding identifier for the query statement, it can further determine whether there is a corresponding restriction on the query statement, and determine whether the query statement type of the query statement is a statistical type; if there is a corresponding restriction on the query statement, and / or the query statement type of the query statement is a statistical type, it can be considered that the query statement already has certain restrictions, and there is no need to add corresponding restrictions to the query statement, and the query statement can be directly used to query the database to obtain the corresponding data from the database; if there is no corresponding restriction for the query statement, and the query statement type of the query statement is not a statistical type, it means that there is no corresponding restriction for the query statement at present, and the corresponding restriction needs to be added, and then step S103 can be executed to add corresponding restrictions to the query statement.
[0070] In summary, by judging whether there are restrictions in the query statement and whether the query statement type is a statistical type, query statements that already have restrictions and whose query statement type is a statistical type can be effectively filtered out, and repeated addition of corresponding restrictions to the query statement can be effectively avoided.
[0071] S103: Obtain pre-configured default restriction conditions, configure the default restriction conditions for the query statement, and generate a target query statement.
[0072] In the specific process of executing step S103, corresponding default restriction conditions can be set in advance, so that when it is determined that the query statement does not have an identifier and does not meet the data query conditions, the default restriction conditions are configured for the query statement to generate a target query statement, without the user manually configuring the default restriction conditions for the query statement, thereby ensuring the security of the generated target query statement.
[0073] It should be noted that the default restriction condition can be set according to the amount of data required for most business processing in the actual application process, so that the data obtained by querying the database using the target query statement can meet the processing requirements of the corresponding business. For example, the default restriction condition can be data refining limit5000, which can be set according to the actual application, and is not limited in this embodiment of the application.
[0074] S104: Query corresponding data from the database using the target query statement.
[0075] In the specific process of executing step S104, after configuring the default restriction condition for the query statement and generating the target query statement, the target query statement can be used to query the corresponding data from the database. The database can be a MySQL database, which is not limited in this embodiment of the application.
[0076] In an embodiment of the present application, the code logic corresponding to step S101-step S104 can be written based on the Interceptor socket of the mybatis interceptor to generate corresponding classes, and the generated classes can be encapsulated into an SDK, and finally the SDK is configured into the plugins of the mybatis interceptor. In this way, during the mybatis execution, the pre-configured mybatis interceptor can be used to call the configured SDK to execute the data query method provided by the present application, that is, to execute steps S101-step S104, so as to automatically add corresponding restrictions to the query statement in a non-invasive manner, without manually adding restrictions to each query statement, thereby avoiding omissions, and ensuring the security and scalability of the query statement after adding restrictions, while also improving the efficiency of adding restrictions to the query statement.
[0077] The present application provides a data query method, which is applied to a pre-configured mybatis interceptor. When a query statement is detected, the query statement is intercepted, and it is determined whether the query statement has a corresponding identifier; if there is no corresponding identifier in the query statement, it is determined whether the query statement meets the data query condition; if the query statement does not meet the data query condition, the pre-configured default restriction condition is obtained, and the default restriction condition is configured for the query statement to generate a target query statement; the target query statement is used to query the corresponding data from the database. The technical solution provided by the present application can intercept the query statement through the mybatis interceptor before querying the database using the query statement, that is, each time the query statement is detected to exist, the query statement is intercepted, and the omission of the restriction condition is solved by adding the restriction condition manually hard-coded in the prior art; after intercepting the query statement, if it is determined that the query statement does not have an identifier and does not meet the data query condition, it means that there is no corresponding restriction condition on the query statement, and the pre-configured default restriction condition can be automatically added to the query statement, and the corresponding restriction condition can be added without manual hard coding, which ensures the scalability and security of the query statement, and can also prevent the query of a large amount of data from causing memory overflow.
[0078] In order to better understand the data query method provided by this application, the following is an example. Figure 2 As shown, this data query method is applied to the mybatis interceptor.
[0079] A1: When a query statement is detected, determine whether there is a custom annotation on the query statement; if there is a custom annotation on the query statement, execute A2; if there is no custom annotation on the query statement, execute A4.
[0080] A2: Generate the corresponding identifier and key according to the custom annotation on the query statement, and establish the association relationship between the identifier and key of the query statement.
[0081] A3: Use the Spring interceptor to set the query statement identifier in the context of the pre-set thread.
[0082] A4: Determine whether there is an identifier associated with the query statement key in the thread context; if so, execute A5; if not, execute A7.
[0083] A5: Clear the identifier corresponding to the query statement in the online context according to the query statement key.
[0084] A6: Query the corresponding data from the database according to the query statement.
[0085] A7: Determine whether the query statement has a restriction condition and whether the query statement type of the query statement is a statistical type; if the query statement does not have a restriction condition and the query statement type of the query statement is not a statistical type, execute A8; if the query statement has a restriction condition and / or the query statement type of the query statement is a statistical type, execute A6.
[0086] A8: Get the pre-configured default restriction conditions, configure the default restriction conditions for the query statement, and generate the target query statement.
[0087] A9: Use the target query statement to query the corresponding data from the database.
[0088] Based on the data query method provided by the above embodiment of the present invention, correspondingly, the embodiment of the present invention also provides a data query system, such as Figure 3 As shown, the data query system is applied to the pre-configured mybatis interceptor, and the system includes:
[0089] The interception unit 31 is used to intercept the query statement when the query statement is detected;
[0090] A first judgment unit 32, used to judge whether there is a corresponding identifier in the query statement;
[0091] The second judgment unit 33 is used to judge whether the query statement meets the data query condition if there is no corresponding identifier in the query statement;
[0092] The restriction condition configuration unit 34 is used to obtain a pre-configured default restriction condition if the query statement does not meet the data query condition, and configure the default restriction condition for the query statement to generate a target query statement;
[0093] The first data query unit 35 is used to query corresponding data from the database using a target query statement.
[0094] The specific principles and execution processes of each unit in the data query system disclosed in the above embodiment of the present invention are the same as the data query method disclosed in the above embodiment of the present invention. Please refer to the corresponding parts of the data query method disclosed in the above embodiment of the present invention, and no further details will be given here.
[0095] The present application provides a data query system, which is applied to a pre-configured mybatis interceptor. When a query statement is detected, the query statement is intercepted, and it is determined whether the query statement has a corresponding identifier; if there is no corresponding identifier in the query statement, it is determined whether the query statement meets the data query condition; if the query statement does not meet the data query condition, the pre-configured default restriction condition is obtained, and the default restriction condition is configured for the query statement to generate a target query statement; the target query statement is used to query the corresponding data from the database. The technical solution provided by the present application can intercept the query statement through the mybatis interceptor before querying the database using the query statement, that is, each time the query statement is detected to exist, the query statement is intercepted, and the omission of the restriction condition is solved by adding the restriction condition manually hard-coded in the prior art; after intercepting the query statement, if it is determined that the query statement does not have an identifier and does not meet the data query condition, it means that there is no corresponding restriction condition on the query statement, and the pre-configured default restriction condition can be automatically added to the query statement at this time, and the corresponding restriction condition can be added without manual hard coding, which ensures the scalability and security of the query statement, and can also prevent the query of a large amount of data from causing memory overflow.
[0096] Optionally, the second judgment unit includes:
[0097] A third judgment unit is used to judge whether there is a restriction condition in the query statement, and whether the query statement type of the query statement is a preset query statement type;
[0098] A first determining unit, configured to determine that the query statement does not satisfy the data query condition if the query statement does not have a restriction condition and the query statement type of the query statement is not a preset query statement type;
[0099] The second data query unit is used to determine whether the query statement meets the data query condition if there are restriction conditions in the query statement and / or the query statement type of the query statement is a preset query statement type, and use the query statement to query corresponding data from the database.
[0100] Optionally, the data query system provided in the embodiment of the present application further includes:
[0101] A fourth judgment unit, used to judge whether the query statement has a custom annotation;
[0102] An identifier generating unit, used for generating an identifier and a key of the query statement according to the custom annotation of the query statement if the query statement has a custom annotation, and establishing an association relationship between the identifier of the query statement and the key of the query statement;
[0103] The storage unit is used to store the identifier of the query statement in the context of a preset thread.
[0104] Optionally, the first judging unit includes:
[0105] The acquisition unit is used to obtain the key corresponding to the query statement;
[0106] A fifth determination unit, used to determine whether there is an identifier matching the Key of the query statement in the context of the thread;
[0107] A second determining unit is used to determine that the query statement has a corresponding identifier if there is an identifier matching the Key of the query statement in the context of the thread;
[0108] The third determining unit is configured to determine that the query statement does not have a corresponding identifier if there is no identifier matching the Key of the query statement in the context of the thread.
[0109] Optionally, the fifth judgment unit includes:
[0110] A sixth judgment unit, used to judge whether there is an identifier associated with the Key of the query statement in the context of the thread;
[0111] a fourth determining unit, configured to determine that there is an identifier matching the Key in the context of the thread if there is an identifier associated with the Key of the query statement in the context of the thread;
[0112] The fifth determining unit is configured to determine that there is no identifier matching the Key in the context of the thread if there is no identifier associated with the Key of the query statement in the context of the thread.
[0113] Optionally, the data query system provided in the embodiment of the present application further includes:
[0114] A clearing unit, used for clearing the identifier corresponding to the query statement in the context on the line according to the Key of the query statement if there is a corresponding identifier in the query statement;
[0115] The third data query unit is used to query corresponding data from the database according to the query statement.
[0116] Optional, cleaning unit, including:
[0117] A sixth determining unit, configured to obtain the Key of the query statement if the query statement has a corresponding identifier, and determine an identifier associated with the Key of the query statement from the online context;
[0118] The clearing subunit is used to clear the identifier in the online context that is associated with the key of the query statement.
[0119] The present application embodiment provides an electronic device, such as Figure 4As shown, the electronic device includes a processor 401 and a memory 402, the memory 402 is used to store program codes and data for data query, and the processor 401 is used to call program instructions in the memory to execute the steps shown in the data query method in the above embodiment.
[0120] An embodiment of the present application provides a storage medium, which includes a storage program, wherein when the program is running, the device where the storage medium is located is controlled to execute the data query method shown in the above embodiment.
[0121] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, in which the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0122] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0123] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
[0124] The above are only preferred embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A data query method, characterized in that: Applied to the pre-configured mybatis interceptor, including the method includes: When a query statement is detected, intercepting the query statement; Determine whether there is a corresponding identifier for the query statement; If there is no corresponding identifier in the query statement, determine whether the query statement meets the data query condition; If the query statement does not satisfy the data query condition, obtain a pre-configured default restriction condition, configure the default restriction condition for the query statement, and generate a target query statement; The target query statement is used to query corresponding data from the database.
2. The method according to claim 1, characterized in that The determining whether the query statement satisfies the data query condition includes: Determining whether there is a restriction condition in the query statement and whether the query statement type of the query statement is a preset query statement type; If the query statement does not have a restriction condition, and the query statement type of the query statement is not the preset query statement type, determining that the query statement does not meet the data query condition; If the query statement has restriction conditions, and / or the query statement type of the query statement is the preset query statement type, it is determined that the query statement meets the data query condition, and the query statement is used to query corresponding data from the database.
3. The method according to claim 1, characterized in that: The method further comprises: Determine whether the query statement has a custom annotation; If the query statement has a custom annotation, generate an identifier and a key of the query statement according to the custom annotation of the query statement, and establish an association relationship between the identifier of the query statement and the key of the query statement; The identifier of the query statement is stored in a preset thread context.
4. The method according to claim 3, characterized in that: The determining whether the query statement has an identifier includes: Get the Key corresponding to the query statement; Determine whether there is an identifier matching the Key of the query statement in the context of the thread; If there is an identifier matching the Key of the query statement in the context of the thread, determining that the query statement has a corresponding identifier; If there is no identifier matching the Key of the query statement in the context of the thread, it is determined that there is no corresponding identifier for the query statement.
5. The method according to claim 4, characterized in that The determining whether there is an identifier matching the Key of the query statement in the context of the thread includes: Determine whether there is an identifier associated with the Key of the query statement in the context of the thread; If there is an identifier associated with the Key of the query statement in the context of the thread, determining that there is an identifier matching the Key in the context of the thread; If there is no identifier associated with the Key of the query statement in the context of the thread, it is determined that there is no identifier matching the Key in the context of the thread.
6. The method according to claim 3, characterized in that The method further comprises: If the query statement has a corresponding identifier, clear the identifier corresponding to the query statement in the online context according to the key of the query statement; The corresponding data is queried from the database according to the query statement.
7. The method according to claim 6, characterized in that If the query statement has a corresponding identifier, clearing the identifier corresponding to the query statement in the online context according to the key of the query statement includes: If the query statement has a corresponding identifier, obtain the Key of the query statement, and determine the identifier associated with the Key of the query statement from the online context; The identifier associated with the Key of the query statement in the context on the line is cleared.
8. A data query system, characterized in that: Applied to the pre-configured mybatis interceptor, the system includes: An interception unit, configured to intercept a query statement when a query statement is detected; A first judgment unit, used to judge whether the query statement has a corresponding identifier; A second judgment unit, configured to judge whether the query statement satisfies a data query condition if no corresponding identifier exists in the query statement; A restriction condition configuration unit, configured to obtain a pre-configured default restriction condition if the query statement does not satisfy the data query condition, and configure the default restriction condition for the query statement to generate a target query statement; The first data query unit is used to query corresponding data from the database using the target query statement.
9. An electronic device, characterized in that: include: A processor and a memory, wherein the processor and the memory are connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; The memory is used to store a program, and the program is used to implement the data query method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to execute the data query method according to any one of claims 1 to 7.