简体   繁体   中英

How to use Date with grails searchable plugin?

I have a domain class that looks like this

class A {
static searchable = {
    only: ['title','startAt', 'endAt']
}
....
Date startAt
Date endAt
}

and I use a code like this to search

Date today = new Date()
Date endDate = today + 7
def results = A.search(params, {
.....
            le("A.startAt", today)
            ge("A.endAt", endDate)

        }).results

the problem is that the comparison with dates dont worked,

i tried also like this :

class A {
static searchable = {
    only: ['title','startAt', 'endAt']
    startAt format: "yyyyMMdd"
    endAt format: "yyyyMMdd"
}
....
Date startAt
}

and in for search

def results = A.search(params, {
.....
            le("A.startAt", today.format("yyyyMMdd"))
            ge("A.endAt", endDate.format("yyyyMMdd"))

        }).results

but it does not work either

please help me figuring out what I'm doing wrong

finally i find out my error ! i forget to put le and ge inside must{ }

===>

            must{
                le("startAt", searchDay.format("yyyyMMdd"))
            }

            must{
                ge("endAt", today.format("yyyyMMdd"))
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM