Grails - 动态查找器派生日期查询 GORM

Grails - dynamic finders derived date query GORM

我有以下域名class

class Book {
    String title
    Date releaseDate
    Integer daysOnShelf
    Author author
}

如何列出当前日期大于 releaseDate + daysOnShelf 的所有书籍?例如,不要列出 if 2015-02-10 + 5 (releaseDate + daysOnShelf) 因为日期小于现在。

这可以使用 GORM 动态查找器或 Criteria Builder 来完成吗?例如,

 def index(Integer max) {
     def books = Book.findAll {
         releaseDate.plus(daysOnShelf) < new Date()
     }
     respond books
 }

这应该能达到你想要的效果:

Date dateMinusDaysOnShelf = new Date() - daysOnShelf

Book.findAllByReleaseDateLessThan(dateMinusDaysOnShelf)