mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-09 04:57:11 +08:00
feat: 新增查询列映射信息列表接口
提取 QueryTypeEnum 枚举
This commit is contained in:
@@ -18,6 +18,8 @@ package top.charles7c.cnadmin.common.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import top.charles7c.cnadmin.common.enums.QueryTypeEnum;
|
||||
|
||||
/**
|
||||
* 查询注解
|
||||
*
|
||||
@@ -38,7 +40,7 @@ public @interface Query {
|
||||
/**
|
||||
* 查询类型(等值查询、模糊查询、范围查询等)
|
||||
*/
|
||||
Type type() default Type.EQUAL;
|
||||
QueryTypeEnum type() default QueryTypeEnum.EQUAL;
|
||||
|
||||
/**
|
||||
* 多属性模糊查询,仅支持 String 类型属性,多个属性之间用逗号分隔
|
||||
@@ -47,66 +49,4 @@ public @interface Query {
|
||||
* </p>
|
||||
*/
|
||||
String blurry() default "";
|
||||
|
||||
/**
|
||||
* 查询类型
|
||||
*/
|
||||
enum Type {
|
||||
/**
|
||||
* 等值查询,例如:WHERE `age` = 18
|
||||
*/
|
||||
EQUAL,
|
||||
/**
|
||||
* 非等值查询,例如:WHERE `age` != 18
|
||||
*/
|
||||
NOT_EQUAL,
|
||||
/**
|
||||
* 大于查询,例如:WHERE `age` > 18
|
||||
*/
|
||||
GREATER_THAN,
|
||||
/**
|
||||
* 小于查询,例如:WHERE `age` < 18
|
||||
*/
|
||||
LESS_THAN,
|
||||
/**
|
||||
* 大于等于查询,例如:WHERE `age` >= 18
|
||||
*/
|
||||
GREATER_THAN_OR_EQUAL,
|
||||
/**
|
||||
* 小于等于查询,例如:WHERE `age` <= 18
|
||||
*/
|
||||
LESS_THAN_OR_EQUAL,
|
||||
/**
|
||||
* 范围查询,例如:WHERE `age` BETWEEN 10 AND 18
|
||||
*/
|
||||
BETWEEN,
|
||||
/**
|
||||
* 左模糊查询,例如:WHERE `nickname` LIKE '%张'
|
||||
*/
|
||||
LEFT_LIKE,
|
||||
/**
|
||||
* 中模糊查询,例如:WHERE `nickname` LIKE '%雪%'
|
||||
*/
|
||||
INNER_LIKE,
|
||||
/**
|
||||
* 右模糊查询,例如:WHERE `nickname` LIKE '雪%'
|
||||
*/
|
||||
RIGHT_LIKE,
|
||||
/**
|
||||
* 包含查询,例如:WHERE `age` IN (10, 20, 30)
|
||||
*/
|
||||
IN,
|
||||
/**
|
||||
* 不包含查询,例如:WHERE `age` NOT IN (20, 30)
|
||||
*/
|
||||
NOT_IN,
|
||||
/**
|
||||
* 空查询,例如:WHERE `email` IS NULL
|
||||
*/
|
||||
IS_NULL,
|
||||
/**
|
||||
* 非空查询,例如:WHERE `email` IS NOT NULL
|
||||
*/
|
||||
IS_NOT_NULL,;
|
||||
}
|
||||
}
|
||||
|
@@ -35,6 +35,11 @@ public class StringConsts implements StrPool {
|
||||
*/
|
||||
public static final String EMPTY = "";
|
||||
|
||||
/**
|
||||
* 空格
|
||||
*/
|
||||
public static final String SPACE = " ";
|
||||
|
||||
/**
|
||||
* 分号
|
||||
*/
|
||||
|
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.common.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
|
||||
/**
|
||||
* 查询类型枚举
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/4/12 22:56
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum QueryTypeEnum implements BaseEnum<Integer, String> {
|
||||
|
||||
/**
|
||||
* 等值查询,例如:WHERE `age` = 18
|
||||
*/
|
||||
EQUAL(1, "="),
|
||||
/**
|
||||
* 非等值查询,例如:WHERE `age` != 18
|
||||
*/
|
||||
NOT_EQUAL(2, "!="),
|
||||
/**
|
||||
* 大于查询,例如:WHERE `age` > 18
|
||||
*/
|
||||
GREATER_THAN(3, ">"),
|
||||
/**
|
||||
* 小于查询,例如:WHERE `age` < 18
|
||||
*/
|
||||
LESS_THAN(4, "<"),
|
||||
/**
|
||||
* 大于等于查询,例如:WHERE `age` >= 18
|
||||
*/
|
||||
GREATER_THAN_OR_EQUAL(5, ">="),
|
||||
/**
|
||||
* 小于等于查询,例如:WHERE `age` <= 18
|
||||
*/
|
||||
LESS_THAN_OR_EQUAL(6, "<="),
|
||||
/**
|
||||
* 范围查询,例如:WHERE `age` BETWEEN 10 AND 18
|
||||
*/
|
||||
BETWEEN(7, "BETWEEN"),
|
||||
/**
|
||||
* 左模糊查询,例如:WHERE `nickname` LIKE '%s'
|
||||
*/
|
||||
LEFT_LIKE(8, "LIKE '%s'"),
|
||||
/**
|
||||
* 中模糊查询,例如:WHERE `nickname` LIKE '%s%'
|
||||
*/
|
||||
INNER_LIKE(9, "LIKE '%s%'"),
|
||||
/**
|
||||
* 右模糊查询,例如:WHERE `nickname` LIKE 's%'
|
||||
*/
|
||||
RIGHT_LIKE(10, "LIKE 's%'"),
|
||||
/**
|
||||
* 包含查询,例如:WHERE `age` IN (10, 20, 30)
|
||||
*/
|
||||
IN(11, "IN"),
|
||||
/**
|
||||
* 不包含查询,例如:WHERE `age` NOT IN (20, 30)
|
||||
*/
|
||||
NOT_IN(12, "NOT IN"),
|
||||
/**
|
||||
* 空查询,例如:WHERE `email` IS NULL
|
||||
*/
|
||||
IS_NULL(13, "IS NULL"),
|
||||
/**
|
||||
* 非空查询,例如:WHERE `email` IS NOT NULL
|
||||
*/
|
||||
IS_NOT_NULL(14, "IS NOT NULL"),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
}
|
@@ -30,6 +30,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.annotation.Query;
|
||||
import top.charles7c.cnadmin.common.enums.QueryTypeEnum;
|
||||
import top.charles7c.cnadmin.common.exception.BadRequestException;
|
||||
import top.charles7c.cnadmin.common.util.ReflectUtils;
|
||||
import top.charles7c.cnadmin.common.util.validate.ValidationUtils;
|
||||
@@ -146,7 +147,7 @@ public class QueryHelper {
|
||||
// 注意:数据库规范中列采用下划线连接法命名,程序规范中变量采用驼峰法命名
|
||||
String property = queryAnnotation.property();
|
||||
String columnName = StrUtil.toUnderlineCase(StrUtil.blankToDefault(property, fieldName));
|
||||
Query.Type queryType = queryAnnotation.type();
|
||||
QueryTypeEnum queryType = queryAnnotation.type();
|
||||
switch (queryType) {
|
||||
case EQUAL:
|
||||
queryWrapper.eq(columnName, fieldValue);
|
||||
|
Reference in New Issue
Block a user