Map 添加/分配映射键的Groovy方法?

Map 添加/分配映射键的Groovy方法?,map,groovy,Map,Groovy,有没有一种更“常规”的方法或一行程序来实现这一点 def map1 = [:], map2= [foo: "bar"] if (map1.submap) { map1.submap << map2 } else { map1.submap = map2 } defmap1=[:],map2=[foo:bar] if(映射1.submap){ map1.submap使用默认值的: def map1 = map1.withDefault { [ foo: 'bar' ]

有没有一种更“常规”的方法或一行程序来实现这一点

def map1 = [:], map2= [foo: "bar"]
if (map1.submap) {
    map1.submap << map2
}
else {
    map1.submap = map2
}
defmap1=[:],map2=[foo:bar]
if(映射1.submap){

map1.submap使用默认值的

def map1 = map1.withDefault { [ foo: 'bar' ] } 

谢谢,我不知道这个问题。很好的解决方案!现在我在Grails应用程序中以JSON的形式对此映射进行渲染时遇到了另一个问题,但那是另一个问题:D