#foreach指令 js中判断最后一个值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/spt_dream/article/details/80998836

我的例子

<div class="write-title">
        <span class="name">$!userSession.getSessionKey("userInfo").name,</span>您好!欢迎申报“<span>#foreach($o in $bl) 
       $o.RESUMENAME奖  #if($velocityCount != $bl.size())/#end  
        #end
        </span>”!

    </div>


********************下面是解释**********************

首先是#foreach的简单示例:

#foreach( $elem in $allElems)
    $elem</br>
#end

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

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

 

 

$velocityCount 

这个变量在velocity属性文件中定义,在#foreach的时候可以用得上,比如我foreach一个List<User>时,我们可以使用$velocityCount判断完成形如张三,李四的输出(李四后面没有逗号) 

Java代码  

1. #foreach($user in $users)  

2.     #userNode($user)#if($velocityCount != $user.size()),#end   

3. #end  



或 

Java代码  

1.  #foreach($user in $users)  

2.      #if($velocityCount != 1),#end #userNode($user)  

3.  #end  




默认$velocityCount 从1开始。 

猜你喜欢

转载自blog.csdn.net/spt_dream/article/details/80998836
今日推荐