【问题标题】:Grails: Find class property based on DateGrails:根据日期查找类属性
【发布时间】:2015-01-05 19:03:49
【问题描述】:

我有一个使用 Oracle 作为数据库的 Grails 2.4.3 应用程序。

有一个类叫做 User:

class User {

    String userName = ""
    String userPassword = ""
    Date userAdded
}

在控制器中,我使用以下代码查找所有用户名。

def names = User.where { }.projections { property 'userName' }.list()

现在我想根据添加到数据库的日期查找用户名。

例如,如果提供的日期范围在 2014 年 12 月 1 日到 2014 年 12 月 12 日之间,现在我想获取在此期间添加的所有用户名。

有没有简单的方法?

【问题讨论】:

标签: grails


【解决方案1】:

应该这样做

Date start = // get the start date
Date end = // get the end date

def userNames = User.withCriteria {

  ge('userAdded', start)
  le('userAdded', end)

  projections {
    property("userName")
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    • 2014-07-07
    • 2020-05-19
    • 1970-01-01
    相关资源
    最近更新 更多