创建与当前日期匹配的查询 [英] Create Query matching for current date

查看:105
本文介绍了创建与当前日期匹配的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆