grails - 基于日期的Grails查询

标签 grails gorm criteria

想象我有这个 Realm 类:

class Event {

    DateTime startDate
    DateTime endDate
}

我想找到在过去15到30分钟内结束的 Activity 。
我想要类似的东西:
def now = DateTime.now()

def events= Event.withCriteria {
    ge("endDate".plusMinutes(15), now)
    ge("endDate".plusMinutes(30), now)
}

最佳答案

你也可以用普通的日期魔术来做到这一点

def events= Event.withCriteria {
  between "endDate", new Date( now.time - 30 * 60 * 1000 ), new Date( now.time - 15 * 60 * 1000 )
}

关于grails - 基于日期的Grails查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30755528/

相关文章:

angular - 415 Unsupported media Type in http.post Angular 请求

grails - 通过唯一名称绑定(bind)域类

testing - 使 Grails Geb 测试具有事务性

grails - 如何使用createCriteria在Grails中执行深度查询

java - JPA Criteria API 中的订单

java - "IllegalArgumentException occurred calling getter of"使用 SINGLE_TABLE 继承策略运行条件时

gradle - 带有Intellij的Grails 3.2无法扩展插件类

grails - Grails findAll闭包将查询与hasmany字段组​​合在一起

grails - 如何用Grails从子对象按日期排序?

java - org.hibernate.criterion.Order 无法解析字符串的 '.' 属性