在地图内写DSL地图与闭合groovy, [英] writing DSL map inside map with closure groovy,
本文介绍了在地图内写DSL地图与闭合groovy,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用闭包访问地图中的地图,
我有一个地图对象的值是另一个地图对象
例如: -
`
Accessing map inside map with closure, I have a map object the values is another map object e.g:- `
to access the data like this I can issue
def map = [name:"Gromit", likes:"cheese", id:1234]
def map2 =[map1:map]
map2.each{entry ->
println entry.key
entry.value.each {entry1 -> println entry1.key
println entry1.value
}
}
to access a single map i can issue
map.each{entry ->
println entry.key
println entry.value
}
'
$ b
推荐答案
如何在上面的地图例子中写一个DSL?这里是打印内部映射的键和值的插图。尝试此操作:
Here is an illustration of printing the keys and values of the inner map. Try this:
map1=new HashMap()
map2=new HashMap()
map2.put("1","one")
map1.put("map2",map2)
map1.each{ entry1 ->
def innerMap = entry1.value
innerMap.each { entry2 ->
println "key is ${entry2.key}"
println "value is ${entry2.value}"
}
}
这篇关于在地图内写DSL地图与闭合groovy,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文