需要用Velocity处理一个邮件模板,有些逻辑不好直接处理,下面查语法实现拼接的逻辑,亲测可用
foreach指定循环次数
##截取原始字符串 "一,二,三,四,五,六" ,小于20直接输出,大于20只输出20个,同时后缀"等"
#set($escort = $!str.split(','))
#set($person = "")
#if ($escort.size()>20)
#foreach($item in $escort)
#if($velocityCount < 20)
#set ($person = $person + $item+",")
#elseif($velocityCount == 20)
#set ($person = $person + $item+"等")
#end
#end
#else
#set($person = $!str)
#end
截取字符串的部分,然后拼接
##原始字符串"测试-123,华为-235,小米-233,苹果-666" 重新拼接,输出"测试,华为,小米,苹果"
#set($compagnes = $!str.split(','))
#set($accompany = "")
#foreach($item in $compagnes)
#set ($subArray = $item.split("-"))
#if($velocityCount != $compagnes.size())
#set ($accompany = $accompany + $subArray.get(0)+",")
#else
#set ($accompany = $accompany + $subArray.get(0))
#end
#end
网友评论