在 Velocity 中使用 string.split 后如何访问数组元素?
我正在使用 Velocity 模板语言,目前有:
#set ( $stringList = $string.split(",") )
它工作正常,并按预期使用“,”作为分隔符分割字符串。
我的问题是现在如何访问 $stringList 中的每个元素?
我已经尝试过:
$stringList.get(0)
$stringList[0]
$stringList.[0]
${stringList}.get(0)
我在 JIRA 中使用 Velocity,而 JIRA 恰好使用 Velocity 版本 1.4,该版本显然不支持访问上面尝试过的数组。
非常感谢任何帮助。
I am using Velocity Templating Language and currently have:
#set ( $stringList = $string.split(",") )
which works fine and splits the string up using a ',' as a delimiter as expected.
My question is how do i now access each of the elements in the $stringList?
I have tried:
$stringList.get(0)
$stringList[0]
$stringList.[0]
${stringList}.get(0)
I am using Velocity in JIRA and JIRA happens to use Velocity version 1.4 which apparently doesn't have support for accessing arrays as tried above.
Any help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Velocity 1.6 中测试。
Tested in Velocity 1.6.
当我使用 Arrays.asList() 将数组转换为列表,然后使用列表中的方法访问元素时,它就起作用了。
我将以下内容添加到上下文中:
在我使用的速度模板中:
使用如下字符串数组,
我得到了预期的输出:
It works when I convert the array to a List using Arrays.asList() and then use methods from List to access elements.
I add the following to the context:
In velocity template I use:
With a String-Array as follows
I get the expected output:
Source: http://velocity.apache.org/engine/releases/velocity-1.7/user-guide.html#methods
Source: http://velocity.apache.org/engine/releases/velocity-1.7/user-guide.html#methods
也可以像这样将元素推入数组中。
Its also possible to push elements into an array like this.