速度 hasNext 方法

标签 velocity

我试图调用 hasNext Velocity 模板中的方法,以便根据 foreach 循环中的位置影响行为 - 仅 hasNext没有按照文档工作。

这是 Velocity 用户指南的片段,关于 hasNext 的使用:

Velocity also now provides an easy way to tell if you are on the last iteration of a loop:


#foreach( $customer in $customerList )
  $customer.Name#if( $foreach.hasNext ),#end
#end

这是我的版本:
#foreach ($nav_item in $priNavItems)
  ...
  #if ( $foreach.hasNext )
    <img alt="" class="dive" src="/olp-theme/images/custom/dive.png">
  #end
#end

有没有人成功地在 #foreach 中调用此方法?在速度模板中循环?也许使用不同的名称(例如 $velocityCount 用于计数)?

任何/所有建议和/或方向表示赞赏 - 谢谢!

最佳答案

Velocity 1.6.3 不支持此功能; $foreach.hasNext功能由 ForeachScope 提供类 1.7+ ( docs )。

在线文档是指当前版本;使用早期版本时,您需要引用该特定版本的文档。

关于速度 hasNext 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7796653/

相关文章:

java - 用java替换word文档模板中的变量

java - 我可以使用 Maven 插件更新文件内容吗?

java - Apache 速度 : Is there a standard way of verifying the correctness of a template from the command line?

java - Java 的 Velocity EscapeTool

java - spring + Velocity如何处理开发和生产之间的URL?

java - 在速度模板中以相同的方式设置所有数字的格式

java - 从 Spring MVC 应用程序发送带有图像的 Velocity 模板化电子邮件

java - Velocity - 使用 jQuery 时如何避免 ParseErrorException?

java - 在速度模板中同时迭代两个列表

themes - 是否可以将 Liferay 的版本号传递到主题的 Velocity 模板中?