Grails (Hibernate) 标准查询

发布于 2024-09-28 11:54:36 字数 145 浏览 3 评论 0原文

我的 Grails 应用程序中有一个域类,如下所示:

class Event {
    Date date
}

我想编写一个条件查询来选择某年某月发生的事件,有什么建议吗?

谢谢, 大学教师

I have a domain class in my Grails app that looks like this:

class Event {
    Date date
}

I want to write a criteria query that selects events that occurred in a certain month of a certain year, any suggestions?

Thanks,
Don

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亣腦蒛氧 2024-10-05 11:54:36

您可能只使用 Between :

def firstDayOfMonthInYear, lastDayOfMonthInYear;

/* set the two values using Calendar or some other mechanism */

Event.withCriteria {
    between('date', firstDayOfMonthInYear, lastDayOfMonthInYear)
}

我不确定 Between 的包容性 - 如果两端都不包含,您可能需要调整开始/结束日期。

You could probably just use between:

def firstDayOfMonthInYear, lastDayOfMonthInYear;

/* set the two values using Calendar or some other mechanism */

Event.withCriteria {
    between('date', firstDayOfMonthInYear, lastDayOfMonthInYear)
}

I'm not certain of the inclusivity of between - you may need to adjust your start/end dates if it's not inclusive on both ends.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文