(快速參考)

findWhere

用途

使用對應於網域類別屬性名稱的名稱參數來執行查詢,傳回第一個符合的結果。

範例

給定網域類別

class Book {

   String title
   Date releaseDate
   String author

   static constraints = {
      releaseDate nullable: true
   }
}

您可以使用以下格式查詢

def book = Book.findWhere(author: "Stephen King", title: "The Stand")

boolean isReleased = Book.findWhere(author: "Stephen King",
                                    title: "The Stand",
                                    releaseDate: null) != null

說明

參數

  • queryParams - 要用於查詢的 Map 鍵值對