当我在Apache官方网站上找到velocity项目指南时,我们无法通过#set
使用 boolean 变量,但在我的项目中使用时它也可以工作。
#set($isRight=true)
#if($isRight)
##execute
#end
#set($isRight=false)
#if($isRight)
##not execute
#end
我想知道velocity是否支持#set
boolean 变量以及我使用的方式是否合法。
最佳答案
经验表明您的示例有效,但您是对的,文档没有明确说明您可以使用 #set
指令为变量分配 boolean 值(其中有 meticulously detailed cases 并且缺乏有关 boolean 的信息)。
因此,如果您想确保编写的代码与文档 100% 兼容,那么您可以使用其他值来代替显式的 boolean 值,即 according to the documentation将转换为 boolean 值。他们是例如0
表示 false
,1
表示 true
。
那么你的示例将如下所示:
#set ($isRight = 1)
#if ($isRight)
## execute
#end
#set ($isRight = 0)
#if ($isRight)
## not execute
#end
关于Java速度虚拟机文件#set使用 boolean 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31384395/