# query-dsl-plus
**Repository Path**: mose-x/query-dsl-plus
## Basic Information
- **Project Name**: query-dsl-plus
- **Description**: 约定俗成......一种接口通用的查询方法,简化开发,增强性能,让更多的精力放在更复杂的业务上。即--按照约定,将查询条件封装成string,前端随时随意更改,但是后台不用任何调整,一个查询接口就能完成绝大多数条件查询。
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: https://gitee.com/mose-x/query-dsl-plus
- **GVP Project**: No
## Statistics
- **Stars**: 14
- **Forks**: 3
- **Created**: 2023-09-03
- **Last Updated**: 2025-09-08
## Categories & Tags
**Categories**: Uncategorized
**Tags**: QueryDSL, JPA
## README
# query-dsl-plus
#### 前言
由于喜欢使用JPA,所以后续就接触了query-dsl,但是随着需求的变更,数据查询条件也会越来越复杂(这个和jpa没关系,就算使用mybatis也一样),往往前端改动了,后端还需要做调整,很是麻烦,想着将查询条件封装成string,随时可以更改,一个查询接口就能完成绝大多数条件查询。
#### 简介
1. 前台通过字符串传递变量查询参数
2. 后端封装查询场景,一种查询所有数据的方法
-- --
即: 任何实体,都只需要5个接口, del,getById,add,update,list
其中list接口即通用查询接口(一个search参数搞定所有需求)
-- --
#### 在使用querydsl-plus之前
1. webapi使用如下

2. service 像这样写,或者更难(参数超级多,或者干脆用body传递),或者随时可能更改需求,导致参数发生变化

##### 如果使用了 querydsl-plus, 如下所示, 会变得非常简单


#### Postman 示例
##### 在实际操作中,需要使用编码URI,这里为了方便显示,所以全部没有转换




#### 快速导入
##### 11-
~~~xml
cn.ljserver.tool
query-dsl-plus
2.0.2
~~~
##### 17+
~~~xml
cn.ljserver.tool
query-dsl-plus
3.0.0
~~~
#### 私有安装教程
1. 拉取query-dsl-plus代码仓库
2. 发布到自己私有到maven服务器
3. 在你项目的pom.xml文件中引入
#### 快速上手
1. DAO 继承 QuerydslBinderCustomizer
2. Service 继承 SearchService
3. 方法使用示例
// 搜索字符串,由前端传递, 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