添加到列表中速度真实显示 [英] Adding to List Prints true in Velocity
问题描述
我正在尝试将一些字符串值添加到Velocity中的列表中.当我运行代码时,它可以正常工作.但是添加值的行显示为true.在Velocity中总是这样吗?我是Velocity模板的新手,所以自己无法弄清楚.
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
它是带有嵌套foreach的较大代码的一部分.它有两个匹配项,因此输出为:
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!
推荐答案
Java's List#add
method returns boolean, that's why this return value is printed in your html output.
您只需将add方法的输出分配给虚拟变量即可将其隐藏:
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
这篇关于添加到列表中速度真实显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!