第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

添加 X 小時(shí) - @Query - Spring Data JPA

添加 X 小時(shí) - @Query - Spring Data JPA

守著一只汪 2021-08-04 10:19:22
我嘗試在 Spring Data JPA Repository 中創(chuàng)建一種不同的方法,該方法應(yīng)該將給定的小時(shí)數(shù)添加到時(shí)間戳中。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);}它無(wú)法正常工作,因?yàn)樗洪g隔 '1 小時(shí)' * :hoursAgo確切地:'1小時(shí)'IDE 下劃線并給出此錯(cuò)誤:<'表達(dá)式'>、<'運(yùn)算符'>、GROUP、HAVING 或 ORDER 預(yù)期。我試過(guò)做一些研究,并找到我應(yīng)該如何將給定的時(shí)間添加到 creationTime 但在任何地方都找不到。
查看完整描述

3 回答

?
米琪卡哇伊

TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊

我不相信 PostgreSQL 允許傳遞INTERVAL需要帶有interval '1 day'-style 輸入的硬編碼字符串的 語(yǔ)句;但是,您可以通過(guò)將字符串轉(zhuǎn)換為間隔來(lái)實(shí)現(xiàn)此目的。

嘗試將代碼中的 SQL 查詢更改為:

select a from ActivationCode a where a.creationTime + (:hoursAgo||' hour')::interval <=  CURRENT_TIMESTAMP and a.type = :type and a.account = account

或者,我剛剛找到了以前的 StackOverflow 答案,這值得一試,但可能有同樣的問(wèn)題(假設(shè)它與 Spring Data JPA 的查詢解析器有關(guān)):

select a from ActivationCode a where a.creationTime + :hoursAgo * INTERVAL '1 hour' <=  CURRENT_TIMESTAMP and a.type = :type and a.account = account



查看完整回答
反對(duì) 回復(fù) 2021-08-04
?
MM們

TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個(gè)贊

就像a_horse_with_no_name說(shuō)我必須使用本機(jī)查詢來(lái)做類似的事情,所以我改變了我的方法:

  @Query(value = "select * from activation_codes a where a.type = :type and a.id_account = :id_account and a.creation_time <= NOW() - :hoursAgo * INTERVAL '1 hour'", nativeQuery = true)
  List<ActivationCode> getAllAddedAtLeastXHoursAgo(@Param("id_account") int id_account, @Param("type") int type, @Param("hoursAgo") int hoursAgo);

它工作正常。感謝所有幫助。


查看完整回答
反對(duì) 回復(fù) 2021-08-04
  • 3 回答
  • 0 關(guān)注
  • 233 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)