我有一个域类反馈
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()methiod中编写这些条件。
我在这里尝试过的
def feedbackList = Feedback.createCriteria().list(
) {
eq('isMailSent ', false)
/** here condition (createdOn - cuurent time) >= 15 minutes **/
}
最佳答案
这是一个如何完成此操作的示例。我将其详细说明了一下,以便于阅读。
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)
}
关于hibernate - 如何在grails createCriteria()中编写条件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21361307/