小编Ale*_*lex的帖子

Groovy/Grails LinkedHashMap表现得很奇怪

我在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的内容.

这种行为是预期的还是已知的?

grails groovy linkedhashmap

4
推荐指数
1
解决办法
6439
查看次数

Grails GORM'或'不与协会合作

在下面的例子中,我希望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)

grails associations h2 grails-orm

3
推荐指数
1
解决办法
2082
查看次数

标签 统计

grails ×2

associations ×1

grails-orm ×1

groovy ×1

h2 ×1

linkedhashmap ×1