假设我有以下域类:
class Book {
String title
String author
byte[] largeCoverArtImage
}
我有一个不需要显示的 ListView
largeCoverArtImage
,如何使用 GORM Criteria 执行以下 SQL 查询?select title, author from Book
最佳答案
您可以运行 HQL 查询以使用 executeQuery 选择单个列:
def titlesAndAuthors = Book.executeQuery('select title, author from Book')
这将返回一个 Object[] 列表,例如
for (row in titlesAndAuthors) {
String title = row[0]
String author = row[1]
...
}
关于hibernate - 使用 Gorm 查询列子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3209483/