- The foreground passes variable query parameters through strings
- The backend encapsulates the query scenario, a method that query all data
- One search parameter for all requirements
- webapi like this
- service like this, either it's harder (super many parameters, or simply passed with body), or the requirements may change at any time, causing the parameters to change
In practice, you need to use the encode URI, Here for the convenience of display, so all did not convert
<dependency>
<groupId>cn.ljserver.tool</groupId>
<artifactId>query-dsl-plus</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>cn.ljserver.tool</groupId>
<artifactId>query-dsl-plus</artifactId>
<version>3.0.0</version>
</dependency>
- pull the query-dsl-plus repository
- deploy to you maven repository
- import into you project pom.xml
-
DAO extends QuerydslBinderCustomizer
-
Service extends SearchService
-
function use // search string, passed by the frontend, example: search age>18 and addr=addr
String search = "age>18,addr:addr";
BooleanExpression exp = this.buildPredicate(search, TestEntity.class);
case ":" eq, example: search=name:jack, like sql >> name="jack"
case ">" gt, example: search=age>18, like sql >> age>18
case "<" lt, example: search=age<18, like sql >> age<18
case ")" goe, example: search=age)18, like sql >> age>=18
case "(" loe, example: search=age(18, like sql >> age<=18
case "!" né, example: search=age!18, like sql >> age!=18 or age<>18
case "*" like, example: search=name*%abc%, like sql >> name like "%abc%"
case "^" not like, example: search=name^%abc%, like sql >> name not like "%abc%"
case "@" in, example: search=name@a|b|c, like sql >> name in ("a","b","c")
case "#" contains, example: search=name#abc, like sql >> contains (name,"abc")
case "~" or, example: search=name:abc~age:18, like sql >> name="abc" and age=18
case "|" list separator, example: search=name@a|b|c, like sql >> name in ("a","b","c")
other "," params split,more than 2 params, use the "," to separated <br>