Velocity代码生成:检查是否输入了$foreach?
我尝试修改用于代码生成的 vsl 文件,以检查是否实际进入了 foreach 循环以及是否要执行初始化代码。我尝试了类似java的.length> 0 但这不起作用:
myMethod() {
#if (${reference.attributes}.length > 0)
[some init code]
#foreach ($attribute in ${reference.attributes})
#some_macro($attribute)
#end
[some other code related to stuff created in the
#end
}
正确的方法是什么?
谢谢。
I try to modify a vsl file for code generation to check whether a foreach loop is actually entered and the initialization code is to be performed at all. I tried java-like .length > 0 but that does not work:
myMethod() {
#if (${reference.attributes}.length > 0)
[some init code]
#foreach ($attribute in ${reference.attributes})
#some_macro($attribute)
#end
[some other code related to stuff created in the
#end
}
What's the correct way?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用
size()
方法。这适用于集合和数组(从 Velocity 1.6+ 开始)。Call the
size()
method. This will work on both collections and arrays (as of Velocity 1.6+).