创建与当前日期匹配的查询 [英] Create Query matching for current date
问题描述
可能重复:
在JPA查询中使用CURRENT_DATE的示例
Possible Duplicate:
Example of using CURRENT_DATE in JPA query
我正在尝试向存储库中添加查询,以将数据库中存储的日期与当前日期进行比较.
I am trying to add a query to my repository to compare a date stored in the db against the current date.
我的查询是这样的:
@Query("Select c from Customer c where c.terminated != 1 or c.terminationDate > <currentDate>")
public List<Customer> getTerminatedCustomers();
我可以为<currentDate>
插入什么?
如果一切都失败了,我可以向该方法添加一个参数,并将当前日期传递给查询,如下所示.但是,如果可能的话,我希望有一个更优雅的解决方案.
If everything fails I could add a parameter to the method and pass the current date to the query like this. But I would prefer a more elegant solution, if possible.
推荐答案
This question is actually a duplicate of this one. According to the Java Persistence API specification section 4.6.17.2.3 there are predefined functions CURRENT_DATE
, CURRENT_TIME
and CURRENT_TIMESTAMP
. So the query would have to be defined as
select c from Customer c where c.terminated != 1 or c.terminationDate > CURRENT_DATE
这篇关于创建与当前日期匹配的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!