我有一个域对象。
class Post {
User user
String subject
String body
Date dateCreated
}
我该如何解决这个问题?直接 GORM、HQL 或标准是更好的方法吗? 我不知道什么样的日期操作(“today eq”)适用于标准。
最佳答案
我可能会进行命名查询
class Post {
User user
String subject
String body
Date dateCreated
static namedQueries = {
todaysPosts {
def now = new Date().clearTime()
between('dateCreated', now, now+1)
}
}
}
然后你可以像这样使用它:
Post.todaysPosts.count()
或
Post.todaysPosts.list()
Post.todaysPosts.list(max: 10, offset: 5)
你甚至可以这样做
Post.todaysPosts.findAllByUser(user)
Here更多关于命名查询的内容
关于hibernate - Grails - 查找用户今天创建的所有帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6456061/