querydsl - 想比较日期,但不能应用 SQLExpression.date(java.time.LocalDate)

标签 querydsl

我之前有这样的查询:

public List<Human> findAllHumansWithPets(){

    QHuman human = QHuman.human;
    QPet pet = QPet.pet;

    JPAQuery query = new JPAQuery(entityManager);

    //Joda-Time
    LocalDate first = new LocalDate(1990, 01, 01);
    LocalDate last = new LocalDate(1990, 02, 01);

    return query.from(human)
            .innerJoin(human.pet, pet)
            .where(SQLExpressions.date(human.age).between(first.toDate(), last.toDate()))
            .list(order);
}

它工作得很好。现在我更新了 age我的 Human POJO 中的变量使用 java.time.LocalDate 而不是 org.joda.time.LocalDate。 Querydsl 不喜欢那样,现在提示 SQLExpression.date 的参数.
    //java.time.LocalDate
    LocalDate first = LocalDate.of(1990, 01, 01);
    LocalDate last = LocalDate.of(1990, 02, 01);

    return query.from(human)
            .innerJoin(human.pet, pet)
            .where(SQLExpressions.date(human.age).between(first, last))
            .list(order);
    }

DateTimeExpression<java.lang.Comparable> in SQLExpressions cannot be applied to com.mysema.query.types.path.DatePath<java.time.LocalDate>



我似乎无法找到有关此问题的任何解决方法。防止回到 Joda-Time 会很好。有什么建议?

最佳答案

DateExpression.currentDate(LocalDate.class).between(..., ...)
DateExpression.currentDate(LocalDateTime.class).between(..., ...)

关于querydsl - 想比较日期,但不能应用 SQLExpression.date(java.time.LocalDate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33569982/

相关文章:

spring-boot - Spring Boot/Gradle/Querydsl项目有相同的依赖依赖不同版本的另一个依赖

hibernate - QueryDsl 交叉联接返回零个元素

elasticsearch - 如何基于聚合输出值在Elasticsearch中获取文档?

Querydsl - 寻呼功能

java - QuerydslBinderCustomizer 在 Spring Data JPA 2.0.7 中不起作用

jpa - querydsl 将多个查询合二为一

sql - 像自定义 dsl 查询一样将 Sql 转换为 ElasticSearch?

java - Querydsl 更新子句填充跳过 bean 空值属性

使用 And 和 Or 条件的 Elasticsearch 查询

java - 使用 QueryDSL 和 Spring 的 Repository 编写跨表查询