Author{ 
 String name; 
 List<Book> books 
 static hasMany= [books: Book] 
} 
Book{ 
 int number_of_pages; 
 String name; 
} 

我想查询和获取按 number_of_pages排序的特定作者的前十本书

请您参考如下方法:

使用HQL,您可以执行以下操作:

    def query = "select book from Author author join author.books book where author=:author order by book.number_of_pages" 
    def books = Author.executeQuery(query, [author: author], [max: 10]) 

注意:您应该将 number_of_pages重命名为 numberOfPages。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!