list转map
#function list2map($list, $key, $field)#if ($vs.util.isList($list) and $vs.util.isString($key))#set($map = $vs.util.newMap())#foreach($row in $list)#set($value = $row)#if (!$vs.util.isNull($field))#set($value = $row.get($field))#end$map.put($row.get($key), $value)#endreturn $map#endreturn null
#end
#set($map = @list2map($list, $key, $field))
list转map:动态脚本模式
#function list2mapByScript($list, $key, $field)#if ($vs.util.isList($list) and $vs.util.isString($key))#set($map = $vs.util.newMap())#foreach($row in $list)#set($value = $row)#if (!$vs.util.isNull($field))#set($value = $row.get($field))#end#set($script = 'return $row.' + $key)$map.put($vs.proc.executeScript($script, $vs.util.newMap('row', $row)), $value)#endreturn $map#endreturn null
#end
#set($map = @list2mapByScript($list, $key, $field))
list转map:高阶函数
#function list2mapByFun($list, $keyFun, $valueFun)#if ($vs.util.isList($list) and $vs.util.isMap($keyFun))#set($map = $vs.util.newMap())#foreach($row in $list)#set($value = $row)#if ($vs.util.isMap($valueFun))#set($value = $valueFun.fun($row))#end$map.put($keyFun.fun($row), $value)#endreturn $map#endreturn null
#end
#set($map = @list2mapByFun($list, $vs.util.newMap('fun', @keyFun), $vs.util.newMap('fun', @valueFun)))