Query statement generation method, dynamic query method and system, equipment and medium

By defining the field names and query operations of the query object through annotations, dynamic query statements are generated, which solves the problems of code redundancy and syntax error detection difficulties in JPQL queries, and improves development efficiency and query flexibility.

CN118916376APending Publication Date: 2024-11-08CHONGQING JINKANG NEW ENERGY VEHICLE CO LTD

Patent Information

Application Number
CN202410971833.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-19
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

Traditional JPQL queries have problems with code redundancy and syntax error detection in JPA, resulting in inefficient development.

Method used

Through annotation, field names, query operations and grouping information are defined for query objects, and dynamic query statements are generated, supporting multi-group queries and subclass inheritance of parent classes, improving code reuse rate and security.

Benefits of technology

It realizes code reuse and security improvement, reduces code intrusion, supports multi-group queries, and improves query flexibility and management refinement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916376A_ABST
    Figure CN118916376A_ABST
Patent Text Reader

Abstract

The invention provides a query statement generation method, a dynamic query method and system, equipment and a medium. The query statement generation method comprises the steps of responding to a screening condition input by a user on a target query interface, and obtaining a target annotation according to the screening condition and a corresponding query object; wherein the target annotation comprises a field name corresponding to the target attribute and / or the target method, a query operation corresponding to the field name and grouping information; generating a corresponding query condition clause based on a screening condition corresponding to the field name and a corresponding query operation; grouping and splicing the query condition clauses according to the grouping information to generate a target query condition; and generating a target query statement according to the preset query content and the target query condition corresponding to the target query interface. According to the method, the field name, the query operation and the grouping information are defined for the query object in an annotation manner based on the characteristics of the class, so that the code reuse rate and security are improved, and the code intrusion is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a query statement generation method, a dynamic query method and system, device, and medium. Background Art

[0002] JAVA is a widely used programming language that provides rich APIs and frameworks to support various application development needs, including Web applications, desktop applications, mobile applications, etc.

[0003] JPA (Java Persistence API) is a Java API for object-relational mapping (ORM) provided by JDK 5.0 and above. The main goal of JPA is to provide persistence standards for POJO (Plain Old Java Object), so that developers can easily map Java objects to relational databases and perform operations such as adding, deleting, modifying and querying objects.

[0004] JPQL (Java Persistence Query Language) is the abbreviation of Java Persistence Query Language, which is a query statement specification defined in JPA.

[0005] As JPA is increasingly used, traditional JPQL queries have exposed many shortcomings. For example, different JPQL strings must be written for different query requirements, resulting in code redundancy. In addition, the Java compiler cannot detect syntax errors in JPQL strings at compile time, and can only throw runtime exceptions after executing JPQL statements at runtime, requiring developers to rework, resulting in low development efficiency. Summary of the invention

[0006] In order to solve the above technical problems, the present application provides a query statement generation method, a dynamic query method and system, a device, and a medium.

[0007] This application solves the above technical problems through the following technical solutions:

[0008] In a first aspect, the present application provides a query statement generation method, comprising:

[0009] In response to a user inputting a screening condition in a target query interface, obtaining a target annotation according to the screening condition and a corresponding query object;

[0010] The target annotation includes the field name corresponding to the target attribute and / or target method, the query operation corresponding to the field name, and the grouping information;

[0011] Generate a corresponding query condition clause based on the screening condition corresponding to the field name and the corresponding query operation;

[0012] Grouping and concatenating the query condition clauses according to the grouping information to generate a target query condition;

[0013] A target query statement is generated according to the preset query content corresponding to the target query interface and the target query condition.

[0014] Optionally, the group information includes a group name and a connection relationship within the group;

[0015] The step of generating the target query condition comprises:

[0016] Grouping the query condition clauses according to the group names corresponding to the query condition clauses;

[0017] Connecting the query condition clauses in the same group according to the intra-group connection relationship to obtain a query condition combination;

[0018] The different query condition combinations are connected according to a preset connection relationship to obtain the target query condition.

[0019] Optionally, the step of grouping the query condition clauses according to the group names corresponding to the query condition clauses includes:

[0020] Grouping the first query condition clauses corresponding to the same group name into the same group;

[0021] Grouping the second query condition clauses that do not have the same group name into a default group;

[0022] Among them, the intra-group connection relationship of the default group is "AND".

[0023] Optionally, the step of acquiring the target annotation according to the screening condition and the corresponding query object includes:

[0024] Traversing the properties and methods of the query object, determining that the property covered by the screening condition is a target property, and determining that the method covered by the screening condition is a target method;

[0025] The target annotation is determined according to the annotations of the target attribute and the target method respectively.

[0026] Optionally, the step of determining the target annotation according to the annotations of the target attribute and the target method respectively comprises:

[0027] Determine whether the target attribute and the target method have annotations respectively;

[0028] If it exists, the annotation is verified according to the screening condition and the preset verification rule, and the annotation that passes the verification is determined as the target annotation.

[0029] In a second aspect, the present application provides a dynamic query method, comprising:

[0030] Generate a target query statement according to the query statement generation method as described in the first aspect;

[0031] Obtain and output the query result corresponding to the target query statement.

[0032] In a third aspect, the present application provides a query statement generation system, comprising:

[0033] An input response module, used to respond to a user inputting a screening condition in a target query interface, and obtain a target annotation according to the screening condition and a corresponding query object;

[0034] The target annotation includes the field name corresponding to the target attribute and / or target method, the query operation corresponding to the field name, and the grouping information;

[0035] Define an acquisition module, which is used to generate a corresponding query condition clause based on the screening condition corresponding to the field name and the corresponding query operation;

[0036] A judgment condition generating module, used for grouping and splicing the query condition clauses according to the grouping information to generate a target query condition;

[0037] The first statement generating module is used to generate a target query statement according to the preset query content corresponding to the target query interface and the target query condition.

[0038] In a fourth aspect, the present application provides a dynamic query system, comprising:

[0039] A second statement generating module, used for generating a target query statement according to the dynamic query statement generating system of the third aspect;

[0040] The query feedback module is used to obtain the query result corresponding to the target query statement and output it.

[0041] In a fifth aspect, the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and used to run on the processor. When the processor executes the computer program, it implements the query statement generation method described in the first aspect, and / or implements the dynamic query method described in the second aspect.

[0042] In a sixth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the query statement generation method as described in the first aspect and / or the dynamic query method as described in the second aspect are implemented.

[0043] On the basis of being in accordance with the common sense in the art, the above-mentioned preferred conditions can be arbitrarily combined to obtain the preferred embodiments of the present application.

[0044] The positive progress of this application is that: based on the characteristics of the class, this application defines the corresponding field name in the database, the query operation corresponding to the field name, and the grouping information required to form the target query condition for the query object through annotations, thereby improving the code reuse rate and security and reducing the code intrusion. Among them, the grouping information defined by annotation can also support multi-group queries. In addition, the parent class can be inherited by the subclass, so that the annotations defined for the attributes and methods in the parent class are effective in all subclasses that inherit the parent class. It is also possible to mask the annotations in the parent class by not annotating or changing the content of the annotation by overriding the methods in the parent class in the subclass, thereby achieving more refined query and management. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 A flowchart of a query statement generation method provided in an embodiment of the present application;

[0046] Figure 2 A schematic diagram of a module of a query statement generation system provided in an embodiment of the present application;

[0047] Figure 3 A schematic diagram of a module of a dynamic query system provided in an embodiment of the present application;

[0048] Figure 4 A flowchart of a dynamic query example provided in an embodiment of the present application;

[0049] Figure 5 A schematic diagram of a module of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] The present application is further described below by way of examples, but the present application is not limited to the scope of the examples.

[0051] In the embodiments of the present application, prefixes such as "first" and "second" are used only to distinguish different description objects, and have no limiting effect on the position, order, priority, quantity or content of the described objects. The use of prefixes such as ordinal numbers to distinguish description objects in the embodiments of the present application does not constitute a limitation on the described objects. For the statement of the described objects, please refer to the description in the context of the claims or embodiments, and no unnecessary limitation should be constituted due to the use of such prefixes. In addition, in the description of the present embodiment, unless otherwise specified, the meaning of "multiple" is two or more.

[0052] In the embodiments of the present application, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0053] The present application embodiment provides a query statement generation method, such as Figure 1 As shown, the query statement generation method includes the following steps:

[0054] S101, in response to a user inputting a screening condition in a target query interface, obtaining a target annotation according to the screening condition and a corresponding query object;

[0055] S102, generating a corresponding query condition clause based on the screening condition corresponding to the field name and the corresponding query operation;

[0056] S103, grouping and concatenating query condition clauses according to the grouping information to generate a target query condition;

[0057] S104: Generate a target query statement according to the preset query content and target query conditions corresponding to the target query interface.

[0058] The data that users want to query is usually stored in a database. Users can query the desired information by entering filtering conditions such as keywords, key words, and values ​​in the target query interface.

[0059] It should be noted that in object-oriented programming, users can describe the state and behavior that instances generated based on the base class should have by defining a base class that contains properties and methods. In object-oriented design, the base class is defined as a class type that contains the commonalities of all entities, also known as the "parent class" or "super class". When building a new class, if there are common features or attributes between two or more classes, a base class is usually defined first to contain these commonalities.

[0060] Based on this, the subclass built by inheriting the above base class can directly inherit the properties and methods defined in the base class without rewriting these codes. When the subclass needs to modify the function of the base class method, it can also rewrite these methods to implement specific functions without changing the parent class code, thereby further improving the reusability of the code.

[0061] When developing and programming, by importing spring-data-jpa (a support library), you can define the corresponding field names of attributes and methods in the database table, the query operations corresponding to the field names, and the grouping information needed to form the query conditions by declaring JPA annotations before declaring the attributes and methods of the class according to actual needs.

[0062] In this embodiment, the query object is an instance created based on the user-defined class (base class or subclass). Therefore, the target annotation in this embodiment is an annotation based on JPA implementation, which is mainly used to mark Java classes, methods, fields, etc. to indicate how to map these Java objects to tables, columns, relations, etc. in the database. And the target annotation should include the field name corresponding to the target attribute and / or target method, the query operation corresponding to the field name, and the grouping information.

[0063] In the existing query function, the filter conditions input by the user are usually superimposed as the target query conditions. The query function is too rigid and single, and cannot meet the needs of users at one time. Or, in addition to entering the filter conditions, the user also needs to enter the combination relationship between the filter conditions, which requires the user to perform cumbersome input operations. Moreover, since the user may not have relevant professional knowledge, the wrong combination relationship may be entered, resulting in the failure to obtain the query results in the end, causing a poor user experience for the user.

[0064] In this embodiment, multiple query condition clauses can be divided into multiple groups according to the grouping information in the target annotation. The query condition clauses in the same group are first connected in the manner defined in the grouping information to construct a query condition combination, and then different query condition combinations are connected in a preset connection manner to obtain the final target query condition, so that the target query condition can contain the contents of multiple query condition combinations, and then based on this target query condition, the query result required by the user can be flexibly obtained.

[0065] Based on this, in one embodiment, step S101 includes:

[0066] S1011, traverse the properties and methods of the query object, determine the properties covered by the screening conditions as target properties, and determine the methods covered by the screening conditions as target methods;

[0067] S1012. Determine the target annotation according to the annotations of the target attribute and the target method respectively.

[0068] For example, a class is defined, including attributes of name and age, and a method for obtaining years of work experience, and corresponding instances are created to describe the staff, and corresponding annotations are declared before the statements declaring the name, age, and years of work experience.

[0069] In the target query interface, users can filter out employees who meet the filter requirements by entering their name, age, and years of work experience, and view detailed information about the employees who meet the filter requirements. However, the filter conditions actually entered by the user are only age and years of work experience. By traversing the properties and methods of the query object, it can be determined that the target property includes age, and the target method includes obtaining years of work experience.

[0070] After determining the target attribute and the target method, in one embodiment, it is usually first determined whether the target attribute and the target method have corresponding annotations. If so, the completeness and legality of the annotations are verified according to the screening conditions. That is, step S1012 specifically includes:

[0071] Determine whether the target attribute and target method have annotations respectively;

[0072] If it exists, the annotation is verified according to the screening conditions and preset verification rules, and the annotation that passes the verification is determined as the target annotation.

[0073] For example, when designing annotations, the expected input format, the type and range of the expected input value can be specified. After the user enters the filter condition, the filter condition entered by the user is verified according to the preset verification rules. For example, the filter condition is compared with the input format expected by the corresponding annotation for completeness verification, and the value of the filter condition is compared with the type and range of the corresponding expected input value for legality verification.

[0074] In step S102, a corresponding query condition clause may be generated according to the field name, the screening condition input by the user, and the query operation corresponding to the field name.

[0075] The query operation corresponding to the field name may be any one of “=”, “>”, “<”, “≥”, “≤”, and “in”.

[0076] Exemplarily, the target annotation includes the field name "age" and the query operation "=" corresponding to the field name. According to the filtering condition input by the user that the age is 35, the corresponding query condition clause "age=35" can be obtained.

[0077] Usually, users will enter multiple filter conditions for combined query. The query condition clause corresponding to each filter condition can be generated in the above manner, and multiple query condition clauses can be spliced ​​according to the grouping information to obtain the final target query statement.

[0078] In one embodiment, the group information includes a group name and a connection relationship within the group.

[0079] For example, the annotation of a property or method can be expressed as:

[0080] @QueryField(

[0081] entity="name",

[0082] condition=FieldCondition.IN,

[0083] group=@QueryGroup(name=”name_and_age_query_group”,

[0084] condition=GroupCondition.OR)

[0085] Among them, entity = "name" means that the field name in the database table is "name", condition = FieldCondition.IN means that the query operation is "in", and group means group information. In group, name = "name_and_age_query_group" means that the group name is "name_and_age_query_group", and condition = GroupCondition.OR means that the intra-group connection relationship of the group name "name_and_age_query_group" is "OR".

[0086] Based on the above grouping information, step S103 includes:

[0087] S1031, grouping the query condition clauses according to the group names corresponding to the query condition clauses;

[0088] S1032, connecting the query condition clauses in the same group according to the intra-group connection relationship to obtain a query condition combination;

[0089] S1033: Connect different groups of query conditions according to a preset connection relationship to obtain a target query condition.

[0090] Specifically, each query condition clause includes a field name, a query operation corresponding to the field name, and a filtering condition. According to the grouping name corresponding to the field name in the query condition clause, the query condition clauses with the same corresponding grouping name can be divided into the same group, and multiple query condition clauses in the same group are connected according to the intra-group connection relationship to obtain the corresponding query condition combination. Then, different query condition combinations are connected according to the preset connection relationship to obtain the final target query condition.

[0091] Exemplarily, the query condition clauses obtained through step S103 include "name in ('Zhang San', 'Li Si', 'Wang Wu')", "age > 35", "work_experience > 5", and "service_experience > 3".

[0092] Among them, "name in ('Zhang San', 'Li Si', 'Wang Wu')" and "age > 35" correspond to the grouping name "name_and_age_query_group", and "work_experience > 5" and "service_experience > 3" correspond to the grouping name "experience_query_group".

[0093] The intra-group connection relationship corresponding to the grouping name "name_and_age_query_group" is "AND", and the intra-group connection relationship corresponding to the grouping name "experience_query_group" is "OR".

[0094] Therefore, the query condition combinations "name in ('Zhang San', 'Li Si', 'Wang Wu') and age > 35" and "work_experience > 5 or service_experience > 3" can be obtained. The preset connection relationship is usually "AND", and correspondingly, the target query condition can be obtained as "(name in ('Zhang San', 'Li Si', 'Wang Wu') and age > 35) and (work_experience > 5 or service_experience > 3)".

[0095] In one embodiment, step S1031 specifically includes:

[0096] Dividing the first query condition clauses with the same corresponding grouping name into the same group;

[0097] Dividing the second query condition clauses without the same corresponding grouping name into the default group;

[0098] Among them, the intra-group connection relationship of the default group is "AND".

[0099] Specifically, first, the first query condition clauses corresponding to the same grouping name are grouped together, and the first query condition clauses in this group are connected according to the intra-group connection relationship corresponding to the grouping name, obtaining a first query condition combination; then, the second query condition clauses without corresponding same grouping name are grouped into a default group, and the second query condition clauses in the default group are connected according to "AND", obtaining a second query condition combination; finally, the first query condition combination and the second query condition combination are connected according to a preset connection relationship, obtaining a target query statement.

[0100] Exemplarily, the query condition clauses obtained through step S103 include "name in ('Zhang San', 'Li Si', 'Wang Wu')", "age > 35", "work_experience > 5", and "level > 3".

[0101] Among them, "name in ('Zhang San', 'Li Si', 'Wang Wu')" and "age > 35" correspond to the grouping name "name_and_age_query_group", "work_experience > 5" corresponds to the grouping name "experience_query_group", and "level > 3" corresponds to the grouping name "level_query_group".

[0102] The intra-group connection relationship corresponding to the grouping name "name_and_age_query_group" is "AND", the intra-group connection relationship corresponding to the grouping name "experience_query_group" is "OR", and the intra-group connection relationship corresponding to the grouping name "level_query_group" is "AND".

[0103] Since except for the query condition clause "work_experience > 5", there are no other query condition clauses corresponding to the grouping name "experience_query_group"; and except for the query condition clause "level > 3", there are no other query condition clauses corresponding to the grouping name "level_query_group", so the query condition combination "name in ('Zhang San', 'Li Si', 'Wang Wu') and age > 35" and the default group "work_experience > 5 and level > 3" can be obtained. The preset connection relationship is usually "AND", and correspondingly, the target query condition can be obtained as "(name in ('Zhang San', 'Li Si', 'Wang Wu') and age > 35) and (work_experience > 5 and level > 3)".

[0104] In step S104, the database table to be accessed and the data columns to be read from the database table can be determined according to the preset query content corresponding to the target query interface, and the final target query statement can be generated in combination with the target query conditions generated previously.

[0105] For example, the function of the target query interface is to query all the information of the personnel who meet the screening conditions from the user table, that is, the preset query content can be expressed as "select * from workers". If the screening condition is employees who are older than 35 and have more than 5 years of work experience or have worked in the company for more than 3 years, the generated target query condition can be expressed as "age>35and(work_experience>5orservice_experience>3)". Combining the preset query content and the target query condition, the generated target query statement can be expressed as "select * from workerswhere age>35and(work_experience>5orservice_experience>3)".

[0106] In an embodiment of the present application, based on the characteristics of the class, the corresponding field names in the database, the query operations corresponding to the field names, and the grouping information required to form the target query conditions are defined for the query objects through annotations. This allows the target query conditions to be dynamically constructed based on the filtering conditions entered by the user. Combined with the preset query content corresponding to the target query interface, it is possible to further dynamically generate the target query statement based on the filtering conditions entered by the user.

[0107] Based on the above method, the code reuse rate and security are improved, and the code intrusion is reduced. And the grouping information defined by annotation can also support multi-group query. In addition, the parent class can be inherited by the subclass, so that the annotations defined for the properties and methods in the parent class are effective in all subclasses that inherit the parent class. The annotations in the parent class can be shielded by not annotating or changing the content of the annotation by overriding the methods in the parent class in the subclass, so as to achieve more refined query and management.

[0108] Corresponding to the above-mentioned embodiment of the query statement generating method, the present application also provides an embodiment of the query statement generating system.

[0109] Figure 2 A module diagram of a query statement generation system provided in an embodiment of the present application, the system comprising:

[0110] An input response module 201 is used to respond to a user inputting a screening condition in a target query interface, and obtain a target annotation according to the screening condition and a corresponding query object;

[0111] The target annotation includes the field name corresponding to the target attribute and / or target method, the query operation corresponding to the field name, and the grouping information;

[0112] A definition acquisition module 202 is used to generate a corresponding query condition clause based on the screening condition corresponding to the field name and the corresponding query operation;

[0113] The judgment condition generating module 203 is used to group and concatenate the query condition clauses according to the grouping information to generate the target query condition;

[0114] The first statement generating module 204 is used to generate a target query statement according to preset query content and target query conditions corresponding to the target query interface.

[0115] For the system embodiment, since it basically corresponds to the method embodiment, the relevant parts can be referred to the partial description of the method embodiment. The system embodiment described above is only illustrative, in which the units described as separate components may or may not be physically separated, and the components of the 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 present application solution.

[0116] The present application also provides a dynamic query method, comprising the following steps:

[0117] Generate a target query statement according to the query statement generation method described above;

[0118] Get the query results corresponding to the target query statement and output them.

[0119] In this embodiment, multiple query condition clauses can be divided into multiple groups according to the grouping information in the target annotation, and the query condition clauses in the same group are first connected in the manner defined in the grouping information to construct a query condition combination, and then different query condition combinations are connected in a preset connection manner to obtain the final target query condition, so that the target query condition can contain the content of multiple query condition combinations, thereby dynamically constructing the target query condition according to the screening condition input by the user. In addition, combined with the preset query content corresponding to the target query interface, it is possible to further dynamically generate a target query statement according to the screening condition input by the user, and based on this target query statement, the query result required by the user can be obtained dynamically and flexibly.

[0120] Corresponding to the above-mentioned embodiment of the dynamic query method, the present application also provides an embodiment of the dynamic query system.

[0121] Figure 3 A module diagram of a query statement generation system provided in an embodiment of the present application, the system comprising:

[0122] A second statement generating module 301, configured to generate a target query statement according to the above-mentioned dynamic query statement generating system;

[0123] The query feedback module 302 is used to obtain the query result corresponding to the target query statement and output it.

[0124] The above dynamic query method and system are described in detail below through a specific example:

[0125] The target query interface usually provides a variety of input boxes or selection boxes for entering filter conditions. The user can enter content in the input box as the filter condition, or select content in the selection box as the filter condition.

[0126] like Figure 4 As shown, after the user enters or selects content in the target query interface, the filter condition is entered. All public methods and properties of the query object corresponding to the filter condition are traversed, and the methods covered by the filter condition are used as target methods, and the properties covered by the filter condition are used as target properties. It is determined whether the target property and target method have annotations respectively. If they exist, the annotations are determined to be complete according to the filter condition. If they are complete, the annotations are determined to be legal according to the preset verification rules. If they are legal, one or more target annotations can be obtained.

[0127] First, according to the screening conditions, the field names in the corresponding target annotations and the query operations, the corresponding query condition clauses are generated. Then, the query condition clauses are grouped according to the group name in the target annotation, and the query condition clauses in the same group are connected according to the intra-group connection relationship corresponding to the group name to obtain the query condition combination. Then, different query condition combinations are connected according to the preset connection relationship to obtain the target query condition, and the target query statement is generated based on the target query condition according to the preset query content corresponding to the target query interface. Finally, the target query statement is handed over to the Repository (a data access component) for execution, that is, the target query statement is used to obtain the corresponding query results from the database and returned to the target query interface for display.

[0128] Figure 5This is a structural diagram of an electronic device shown in an example embodiment of the present application, the electronic device includes a memory, a processor, and a computer program stored in the memory and used to run on the processor, and when the processor executes the computer program, it implements the query statement generation method and / or dynamic query method described in any of the above embodiments. Figure 5 The electronic device 50 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0129] like Figure 5 As shown, the electronic device 50 may be in the form of a general-purpose computing device, for example, it may be a server device. The components of the electronic device 50 may include, but are not limited to: at least one processor 51, at least one memory 52, and a bus 53 connecting different system components (including the memory 52 and the processor 51).

[0130] The bus 53 includes a data bus, an address bus, and a control bus.

[0131] The memory 52 may include a volatile memory, such as a random access memory (RAM) 521 and / or a cache memory 522 , and may further include a read-only memory (ROM) 523 .

[0132] The memory 52 may also include a program tool 525 (or utility) having a set (at least one) of program modules 524, such program modules 524 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0133] The processor 51 executes various functional applications and data processing by running the computer program stored in the memory 52, such as the query statement generation method and / or the dynamic query method provided in any of the above embodiments.

[0134] The electronic device 50 may also communicate with one or more external devices 54 (e.g., keyboards, pointing devices, etc.). Such communication may be performed via an input / output (I / O) interface 55. Furthermore, the electronic device 50 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 56. As shown, the network adapter 56 communicates with other modules of the electronic device 50 via a bus 53. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 50, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.

[0135] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.

[0136] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the query statement generation method and / or the dynamic query method provided in any of the above embodiments is implemented.

[0137] The readable storage medium may include but is not limited to: a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical storage device, a magnetic storage device or any suitable combination of the above.

[0138] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements any of the query statement generation methods and / or dynamic query methods described above.

[0139] Among them, the program code for executing the computer program product of the present application can be written in any combination of one or more programming languages, and the program code can be executed completely on the user device, partially on the user device, as an independent software package, partially on the user device and partially on a remote device, or completely on the remote device.

[0140] Although the specific implementation methods of the present application are described above, those skilled in the art should understand that this is only an example, and the protection scope of the present application is defined by the appended claims. Those skilled in the art may make various changes or modifications to these implementation methods without departing from the principles and essence of the present application, but these changes and modifications all fall within the protection scope of the present application.

Claims

1. A query statement generation method, characterized in that: The query statement generating method comprises: In response to a user inputting a screening condition in a target query interface, obtaining a target annotation according to the screening condition and a corresponding query object; The target annotation includes the field name corresponding to the target attribute and / or target method, the query operation corresponding to the field name, and the grouping information; Generate a corresponding query condition clause based on the screening condition corresponding to the field name and the corresponding query operation; Grouping and concatenating the query condition clauses according to the grouping information to generate a target query condition; A target query statement is generated according to the preset query content corresponding to the target query interface and the target query condition.

2. The query statement generation method according to claim 1, characterized in that: The group information includes a group name and a connection relationship within the group; The step of generating the target query condition comprises: Grouping the query condition clauses according to the group names corresponding to the query condition clauses; Connecting the query condition clauses in the same group according to the intra-group connection relationship to obtain a query condition combination; The different query condition combinations are connected according to a preset connection relationship to obtain the target query condition.

3. The query statement generation method according to claim 2, characterized in that: The step of grouping the query condition clauses according to the group names corresponding to the query condition clauses comprises: Grouping the first query condition clauses corresponding to the same group name into the same group; Grouping the second query condition clauses that do not have the same group name into a default group; Among them, the intra-group connection relationship of the default group is "AND".

4. The query statement generation method according to claim 1, characterized in that: The step of acquiring the target annotation according to the screening condition and the corresponding query object comprises: Traversing the properties and methods of the query object, determining that the property covered by the screening condition is a target property, and determining that the method covered by the screening condition is a target method; The target annotation is determined according to the annotations of the target attribute and the target method respectively.

5. The query statement generation method according to claim 4, characterized in that: The step of determining the target annotation according to the annotations of the target attribute and the target method respectively comprises: Determine whether the target attribute and the target method have annotations respectively; If it exists, the annotation is verified according to the screening condition and the preset verification rule, and the annotation that passes the verification is determined as the target annotation.

6. A dynamic query method, characterized in that: The dynamic query method comprises: Generate a target query statement according to the query statement generation method according to any one of claims 1 to 5; Obtain and output the query result corresponding to the target query statement.

7. A system for generating dynamic query statements, characterized in that: The generation system comprises: An input response module, used to respond to a user inputting a screening condition in a target query interface, and obtain a target annotation according to the screening condition and a corresponding query object; The target annotation includes the field name corresponding to the target attribute and / or target method, the query operation corresponding to the field name, and the grouping information; Define an acquisition module, which is used to generate a corresponding query condition clause based on the screening condition corresponding to the field name and the corresponding query operation; A judgment condition generating module, used for grouping and splicing the query condition clauses according to the grouping information to generate a target query condition; The first statement generating module is used to generate a target query statement according to the preset query content corresponding to the target query interface and the target query condition.

8. A dynamic query system, characterized in that: The dynamic query system comprises: A second statement generating module, configured to generate a target query statement according to the dynamic query statement generating system as claimed in claim 7; The query feedback module is used to obtain the query result corresponding to the target query statement and output it.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and used to run on the processor, characterized in that: When the processor executes the computer program, the query statement generating method according to any one of claims 1 to 5 is implemented, and / or the dynamic query method according to claim 6 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the query statement generation method according to any one of claims 1 to 5 is implemented, and / or the dynamic query method according to claim 6 is implemented.

Citation Information

Patent Citations

  • Method and configuration for generating query condition in annotation way

    CN103020064A

  • Method and device of generating SQL statement automatically

    CN108846101A

  • Annotation-based data query method and device and storage medium

    CN110674200A

  • Query statement determination method and device, equipment, medium and product

    CN117520368A

  • Determining boolean logic and operator precedence of query conditions

    US20080133570A1

Cited By

  • JPA dynamic retrieval method and system based on Java annotation

    CN121412275A