我正在處理一個 jpa 查詢,它需要獲取上次更新時間超過 15 分鐘的所有記錄 我的查詢就像
Select * from user u where u.last_modified >= NOW() - INTERVAL '5 minutes'
我將在我的 jpa 中動態傳遞分鐘數
@Query("Select * from user u where u.last_modified >= NOW() - INTERVAL ':timeInMinutes minutes'")
getRecord(String timeInMinutes);
這不起作用。我想動態地傳遞一分鐘。有人可以幫我解決這個問題嗎
uj5u.com熱心網友回復:
你可以使用這個技巧:
@Query("""
SELECT * from user u WHERE
u.last_modified >= (NOW() - (INTERVAL '1' minutes) * :timeInMinutes)
""", nativeQuery = true)
SomeType getRecord(Long timeInMinutes);
這里的想法是乘以timeInMinutes,1這將永遠給你timeInMinutes。
注意:timeInMinutes 的型別應該是一個數字,而且您也必須使用nativeQuery = true,因為您的查詢不是 JPA 語法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/528172.html
