7

次のドメインクラスがあるとします。

class Book {
  String title
  String author
  byte[] largeCoverArtImage
}

表示する必要のないリストビューがありますがlargeCoverArtImage、GORM基準を使用して次のSQLクエリを実行するにはどうすればよいですか?

select title, author from Book
4

2 に答える 2

7

executeQueryを使用して、個々の列を選択するHQLクエリを実行できます。

def titlesAndAuthors = Book.executeQuery('select title, author from Book')

これにより、Object[]のリストが返されます。

for (row in titlesAndAuthors) {
   String title = row[0]
   String author = row[1]
   ...
}
于 2010-07-09T03:59:12.980 に答える
7

Grails(1.3.7バージョンでテスト済み)では、次のように書くことができます。

def titlesAndAuthors = Book.withCriteria {
        projections {
            property 'title', 'title'
            property 'author', 'author'
        }
}

そして、上記の例のようにObject[]のリストを取得します。

于 2011-05-17T13:34:53.417 に答える