Adding to List Prints true in Velocity

。_饼干妹妹 提交于 2019-12-10 22:15:14

问题


I am trying to add some string values to a list in Velocity. When I run the code it works alright. But the line where it adds the value prints true. Is it always like that in Velocity? I am new to Velocity templates, so cant figure it out myself.

#set ($uniqueInterfaces     =   [])
#if($ipv4interfaceName == $ipv6interfaceName)
    $uniqueInterfaces.add($ipv4interfaceName)
#end

Its part of larger code with a nested foreach. It has two matches in it, so the output is:

true
true

I do not need this true being printed at all!


回答1:


Java's List#add method returns boolean, that's why this return value is printed in your html output.

You can hide it simply by assigning the output of the add method to a dummy variable:

#set ($uniqueInterfaces     =   [])
#if($ipv4interfaceName == $ipv6interfaceName)
    #set ($swallow = $uniqueInterfaces.add($ipv4interfaceName))
#end


来源:https://stackoverflow.com/questions/40032484/adding-to-list-prints-true-in-velocity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!