1

我有三个域类 Author、Comment 和 Book:

class Author {
String name
static hasMany = [books: Book, comments: Comment]
}

class Book {
static belongsTo = [author: Author]
static hasMany = [comments: Comment]
}

class Comment {
static belongsTo = [book: Book, author: Author] 
}

我有以下 mongoDB 查询来查找所有有给定作者评论的书籍。

Comment.findAllByAuthor(author1).collect {
        it.book
    }.unique().findAll { 
        it != null 
}

我如何对这个查询使用分页,即对所有书籍进行分页?

4

1 回答 1

1

对 Book 使用标准查询而不是 Comment:

def c = Book.createCriteria()
def PaginatedBookList = c.list(max: params.max, offset: params.offset) {
    and{
        eq('author',author1)
        isNotNull('comments')
    }
}
于 2012-12-15T15:48:19.470 回答