关于Velocity加减法等四则运算的迷思

  曾今有一个FreeMarker摆在我面前。 我没有好好珍惜, 遇到了Velocity我才想起失去的美好... 


  需求是把PC网页点击、 手机网页点击、App点击相加得到总点击量显示出来:

$article.hits+$article.wapHits+$article.mobileHits
  理想非常美好, 现实输出的是:Number+Number+Number的一个大字符串(想当年。 用FreeMarker的时候。 加减运算直接上, 而现在...)



  据说须要在+号等四则运算符两側都加上空格。 好吧。 尝试下:

$article.hits + $article.wapHits + $article.mobileHits
  尼玛呀, Velocity就是不识别。 给我照样输出大字符串。 我想起了失去的FreeMarker, 耳边响起了《失去的美好》



  好吧, 那就用究极技能(把运算放到Velocity脚本中进行):

#set($total=$article.hits + $article.wapHits + $article.mobileHits)
                $total

  嗯, 能够了, Commit...



原文地址:https://www.cnblogs.com/bhlsheji/p/5124037.html