def query = Person.where {
firstName == "Bart"
}
Person bart = query.find()
其中
目的
定义了一个新的 grails.gorm.DetachedCriteria
实例。
示例
基本查询
连接/析取
def query = Person.where {
(lastName != "Simpson" && firstName != "Fred") || (firstName == "Bart" && age > 9)
}
def results = query.list(sort:"firstName")
属性比较
def query = Person.where {
firstName == lastName
}
关联查询
def query = Pet.where {
owner.firstName == "Joe" || owner.firstName == "Fred"
}
子查询
final query = Person.where {
age > avg(age)
}