我有一个域类反馈
class Feedback{
String name
String email
Date createdOn
Boolean isMailSent
}
I want to fetch all feedbacks with the condition as below
1) isMailSent == false
2) (createdOn - cuurent time) >= 15 minutes
如何在createCriteria()方法中编写这些条件。
我在这里尝试了什么
def feedbackList = Feedback.createCriteria().list(
) {
eq('isMailSent ', false)
/** here condition (createdOn - cuurent time) >= 15 minutes **/
}
答案 0 :(得分:3)
以下是如何完成此操作的示例。我把它做得稍微冗长,所以它更容易阅读。
import groovy.time.TimeCategory
def now = new Date()
def fifteenMinutesAgo = null
use(TimeCategory) {
fifteenMinutesAgo = now - 15.minutes
}
def feedbackList = Feedback.createCriteria().list() {
eq('isMailSent', false)
le('createdOn', fifteeenMinutesAgo)
}