我在Grails 2.0.3中遇到了LinkedHashMap的一些令人困惑的行为.在grails控制台中运行以下脚本:
def m = ["smart-1":[stuff:'asdf']]
println m.getClass()
def p = [id:1]
println m."smart-$p.id"
println m["smart-$p.id"]
println m.get("smart-$p.id")
println m.'smart-1'
println m['smart-1']
println m.get('smart-1')
Run Code Online (Sandbox Code Playgroud)
给出输出:
class java.util.LinkedHashMap
[stuff:asdf]
[stuff:asdf]
null
[stuff:asdf]
[stuff:asdf]
[stuff:asdf]
Run Code Online (Sandbox Code Playgroud)
在集成测试中,我看到了相反的行为 - 我只能使用m.get(GStringImpl)
(相反
m.get(String)
)获取HashMap的内容.
这种行为是预期的还是已知的?
在下面的例子中,我希望Product.searchAll能够匹配添加剂和产品,但它似乎忽略了eq('name', taste)
.
class Additive {
String flavor
static belongsTo = [product:Product]
}
class Product {
String name
static hasMany = [additives:Additive]
static constraints = {
name nullable:true
}
static namedQueries = {
searchAll { taste ->
or {
eq('name', taste)
additives { eq('flavor', taste) }
}
}
searchAdditives { taste ->
additives { eq('flavor', taste) }
}
searchProducts { taste ->
eq('name', taste)
}
}
}
class SearchSpec extends grails.plugin.spock.IntegrationSpec {
def choc, muff
def 'searchAll should return …
Run Code Online (Sandbox Code Playgroud)