dromara / easy-query

java/kotlin high performance lightweight solution for jdbc query,support oltp and olap query,一款java下面支持强类型、轻量级、高性能的ORM,致力于解决jdbc查询,拥有对象模型筛选、隐式子查询、隐式join
http://www.easy-query.com
Apache License 2.0
477 stars 48 forks source link

eq的条件比较的范围,加个直接接受数组的方法 #237

Closed wm26hua closed 1 month ago

wm26hua commented 1 month ago

因为前端时间范围组件,一般给的数据结构是个数组,["2024-06-01 00:00:00","2024-07-31 00:00:00"]

xuejmnet commented 1 month ago

我想了半天发现这个api可能并没有我一开始想的那么简单,首先如果你传入的是null怎么办,默认框架是不会进行过滤的这个时候range函数的处理和空数组处理还有数组内就一个元素的时候处理如果全部改成自适应那么相当于是违反了之前的方式,如果传入空或者null或者一个数组那么range前后又都是null就会和这个api相悖,所以我再三思考还是不打算增加这个api,您可以编写一个util


    public static <TValue> TValue getIndexValueOrNull(TValue[] values,int index){
        if(index<0){
            throw new IllegalArgumentException("index < 0.");
        }
        if(EasyArrayUtil.isEmpty(values)){
            return null;
        }
        if(values.length<=index){
            return null;
        }
        return values[index];
    }

        LocalDateTime[]  times= new LocalDateTime[2];
        List<Topic> list1 = easyEntityQuery.queryable(Topic.class)
                .where(t -> {
                    t.createTime().rangeClosed(getIndexValueOrNull(times, 0), getIndexValueOrNull(times, 1));
                }).toList();