mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-13 14:57:16 +08:00
refactor: 优化通用查询注解多字段模糊查询
This commit is contained in:
@@ -43,10 +43,10 @@ public @interface Query {
|
||||
QueryTypeEnum type() default QueryTypeEnum.EQUAL;
|
||||
|
||||
/**
|
||||
* 多属性模糊查询,仅支持 String 类型属性,多个属性之间用逗号分隔
|
||||
* 多属性模糊查询,仅支持 String 类型属性
|
||||
* <p>
|
||||
* 例如:@Query(blurry = "username,email") 表示根据用户名和邮箱模糊查询
|
||||
* 例如:@Query(blurry = {"username", "email"}) 表示根据用户名和邮箱模糊查询
|
||||
* </p>
|
||||
*/
|
||||
String blurry() default "";
|
||||
String[] blurry() default {};
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
@@ -131,12 +132,11 @@ public class QueryHelper {
|
||||
QueryWrapper<R> queryWrapper) {
|
||||
// 解析多属性模糊查询
|
||||
// 如果设置了多属性模糊查询,分割属性进行条件拼接
|
||||
String blurry = queryAnnotation.blurry();
|
||||
if (StrUtil.isNotBlank(blurry)) {
|
||||
String[] propertyArr = blurry.split(",");
|
||||
String[] blurryPropertyArr = queryAnnotation.blurry();
|
||||
if (ArrayUtil.isNotEmpty(blurryPropertyArr)) {
|
||||
queryWrapper.and(wrapper -> {
|
||||
for (String property : propertyArr) {
|
||||
wrapper.or().like(StrUtil.toUnderlineCase(property), fieldValue);
|
||||
for (String blurryProperty : blurryPropertyArr) {
|
||||
wrapper.or().like(StrUtil.toUnderlineCase(blurryProperty), fieldValue);
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
Reference in New Issue
Block a user