2 领域类,人物和属性
class Person {
static hasMany = [attributes : Attribute]
}
class Attribute{
String key
String value
}
查询 fname:
def c = Person.createCriteria()
def result = c.list{
attributes {
eq("key", "fname")
eq("value", "foo")
}
println result
}
结果:[foo foo ,foo bar]
查询 lname:
def c = Person.createCriteria()
def result = c.list{
attributes {
eq("key", "lname")
eq("value", "bar")
}
println result
}
结果:[bar bar ,foo bar]
查询 lname 或 fname:
def c = Person.createCriteria()
def result = c.list{
or{
attributes {
eq("key", "fname")
eq("value", "foo")
}
attributes {
eq("key", "lname")
eq("value", "bar")
}
}
println result
}
结果:[foo foo ,foo bar ,bar bar]
但如果我将 OR 更改为 And,我没有得到任何结果:
def c = Person.createCriteria()
def result = c.list{
and{
attributes {
eq("key", "fname")
eq("value", "foo")
}
attributes {
eq("key", "lname")
eq("value", "bar")
}
}
println result
}
结果: []