谷神后端list转map

list转map
java 复制代码
/**
 * list2map
 * list转map:支持全量映射、单字段映射。
 * 
 * @param $list:list:列表。
 * @param $key:string:键。
 * @param $field:string:值字段域。
 *
 * @return 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)
		#end
		return $map
	#end
	return null
#end
java 复制代码
// list2map
#set($map = @list2map($list, $key, $field))
list转map:动态脚本模式
java 复制代码
/**
 * list2mapByScript
 * list转map:动态脚本模式。 
 *
 * @param $list:list:列表。
 * @param $key:string:键。
 * @param $field:string:值字段域。
 *
 * @return 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)
		#end
		return $map
	#end
	return null
#end
java 复制代码
// list2mapByScript
#set($map = @list2mapByScript($list, $key, $field))
list转map:高阶函数
java 复制代码
/**
 * list2mapByFun
 * list转map:高阶函数。
 * 
 * @param $list:list:列表。
 * @param $keyFun:map:键函数。
 * @param $valueFun:map:值函数。
 *
 * @return 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)
		#end
		return $map
	#end
	return null
#end
java 复制代码
// list2mapByFun
#set($map = @list2mapByFun($list, $vs.util.newMap('fun', @keyFun), $vs.util.newMap('fun', @valueFun)))
相关推荐
Evand J12 分钟前
【MATLAB例程】TOA和TDOA混合定位,适用于二维平面的高精度定位。锚点数量、位置、测量噪声可自行调节
开发语言·matlab·定位·tdoa
念越34 分钟前
数据结构:栈堆
java·开发语言·数据结构
淮北4941 小时前
pip虚拟环境包的问题
开发语言·python·pip
dear_bi_MyOnly1 小时前
【多线程——线程状态与安全】
java·开发语言·数据结构·后端·中间件·java-ee·intellij-idea
常年游走在bug的边缘1 小时前
掌握JavaScript作用域:从函数作用域到块级作用域的演进与实践
开发语言·前端·javascript
jiaguangqingpanda1 小时前
Day36-20260204
java·开发语言
ctyshr1 小时前
C++编译期数学计算
开发语言·c++·算法
打码的猿1 小时前
Qt对话框不锁死主程序的方法
开发语言·qt
努力写代码的熊大1 小时前
c++异常和智能指针
java·开发语言·c++
Yvonne爱编码2 小时前
JAVA数据结构 DAY5-LinkedList
java·开发语言·python