验证中...
语言: Groovy
分类: 常用工具包
最后更新于 2018-02-03 18:23
DataUtils.groovy
原始数据 复制代码
final class DataUtils {
private DataUtils() {}
private static innerMergeData(data1, data2) {
if (data2 instanceof Map) {
if (data1 instanceof Map) {
data2.each { k, v ->
if (data1.containsKey(k)) {
data1.put(k, innerMergeData(data1.get(k), v))
} else {
data1.put(k, v)
}
}
} else {
data1 = data2
}
} else {
data1 = data2
}
return data1
}
static Map mergeData(Map... datas) {
def data = [:]
datas.each { d ->
data = innerMergeData(data, d)
}
return data
}
static main(args) {
def data1 = [
test: [
lfp: [
login : [
name : '1',
pwd : '1',
remember: '7'
],
user : [
[name: 'u1']
],
product: [
[name: 'p1'],
[name: 'p2']
]
]
]
]
def data2 = [
test: [
lfp: [
login: [
name: 'admin',
pwd : 'admin'
],
user : [
[name: 'u2'],
[name: 'u3']
]
]
]
]
def data = mergeData(data1, data2)
println data
// [test:[lfp:[login:[name:admin, pwd:admin, remember:7], user:[[name:u2], [name:u3]], product:[[name:p1], [name:p2]]]]]
}
}

评论列表( 0 )

你可以在登录后,发表评论

11_float_left_people 11_float_left_close