我尝试在 Spring Data JPA Repository 中创建一种不同的方法,该方法应该将给定的小时数添加到时间戳中。
public interface ActivationCodeRepository extends CrudRepository<ActivationCode, Long> {
@Query(value = "select a from ActivationCode a where a.creationTime + INTERVAL '1 hour' * :hoursAgo <= CURRENT_TIMESTAMP and a.type = :type and a.account = account")
List<ActivationCode> getAllAddedAtLeastXHoursAgo(@Param("account") Account account, @Param("type") int type, @Param("hoursAgo") int hoursAgo);
}
它无法正常工作,因为它:
间隔 '1 小时' * :hoursAgo
确切地:
'1小时'
IDE 下划线并给出此错误:
<'表达式'>、<'运算符'>、GROUP、HAVING 或 ORDER 预期。
我试过做一些研究,并找到我应该如何将给定的时间添加到 creationTime 但在任何地方都找不到。
米琪卡哇伊
MM们
相关分类