2014-01-26 55 views
0

我有一個域類反饋如何寫Grails的條件下個createCriteria()

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 **/ 
     } 

回答

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) 
} 
相關問題