美文网首页前端开发
Velocity(1)——#foreach指令

Velocity(1)——#foreach指令

作者: myHope2017 | 来源:发表于2018-08-31 20:52 被阅读0次

Velocity(1)——#foreach指令 

首先是#foreach的简单示例:

#foreach($elemin$allElems)$elem
#end

上面这个例子中,$allElems可以是一个Vector,一个HashTable,一个数组。

在Velocity中,有一个变量$velocityCount用作循环计数,初始值是1。这个变量的名字和初始值是在velocity.properties文件里配置的。

下面是更多的几个例子:

eg1:

#set($nums=[-2 .. 2])#foreach($iin$nums)$i#end

//-2 -1 0 1 2

eg2:

#foreach($keyin$allElems.keySet())Key:$key ---> Value:$allElems.get($key)
#end

其中,allElems是一个HashTable

相关文章

网友评论

    本文标题:Velocity(1)——#foreach指令

    本文链接:https://www.haomeiwen.com/subject/mivewftx.html