以速度动态构造变量名 [英] construct variable names dynamically in velocity
本文介绍了以速度动态构造变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以将变量的名称动态构造为速度.
I would like to know if it is possible to construct name of variable into velocity dynamically.
即假设我有 6 个变量到速度模板 [name1, name2, name3 .. name6] 我想输出它们.所以我正在寻找类似的东西:
i.e. lets say I've 6 variables into velocity template [name1, name2, name3 .. name6] I would like to output them. So I'm looking in something like:
#foreach ( $counter in [1..6] )
${name${counter}}
#end
有可能吗?
推荐答案
可以使用 #evaluate
指令:
It is possible using the #evaluate
directive:
#evaluate ('$name1')
#set ($d = '$')
#foreach ($i in [1..6])
#set ($varName = "${d}name${i}")
#evaluate($varName)
#end
这篇关于以速度动态构造变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文