简体   繁体   English

如何在Grails可搜索插件中使用Date?

[英]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{ } 我忘了把lege放进must{ }

===> ===>

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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