[英]JPQL Check greater than less than date today in @Query annotation
I want to check weather validTill
date is greater than today
using JPQL. 我要检查的天气
validTill
日期大于today
使用JPQL。 I know that I can achieve this by following. 我知道我可以通过以下方式实现这一目标。
Query q = em.createQuery("select e from MyEntity e where e.validTill > :today ");
and pass the :today
parameter. 并传递
:today
参数。 But this is not I wanted. 但这不是我想要的。 I want to do this using
@Query
annotation in the CrudRepository
in Spring. 我想在Spring的
CrudRepository
中使用@Query
注释来做到这一点。
This is my code segment in the CrudRepository
这是我在
CrudRepository
代码段
@Query("SELECT e FROM MyEntity e WHERE e.validFrom < TODAY")
Iterable<MyEntity> findAllValid();
I don't know what I should put at the place TODAY
to get the today's date. 我不知道我应该把在地方
TODAY
拿到了今天的日期。 Please help me. 请帮我。
I found it. 我找到了。 it's like this..
就像这样..
@Query("SELECT e FROM MyEntity e WHERE e.validFrom < CURRENT_DATE")
Iterable<MyEntity> findAllValid();
CURRENT_DATE
- is evaluated to the current date (a java.sql.Date instance). CURRENT_DATE
- 计算到当前日期(java.sql.Date实例)。
CURRENT_TIME
- is evaluated to the current time (a java.sql.Time instance). CURRENT_TIME
- 计算到当前时间(java.sql.Time实例)。
CURRENT_TIMESTAMP
- is evaluated to the current timestamp, ie date and time (a java.sql.Timestamp instance). CURRENT_TIMESTAMP
- 计算当前时间戳,即日期和时间(java.sql.Timestamp实例)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.