gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:22:10 25 4
gpt4 key购买 nike

我之前有这样的查询:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com