【问题标题】:Sometimes velocity does not substitute有时速度不能替代
【发布时间】:2014-04-14 11:23:59
【问题描述】:

有时以下代码会在模板中生成$position.getComment()。其他领域也一样。但这是偶尔的行为。可能是什么原因以及如何解决?

#if($position.hasComment())
    <td>$position.getComment()</td>
#else
    <td class="empty">&mdash;</td>
#end

职位的评论是字符串,hasComment 正在关注

public boolean hasComment() {
    return comment != null;
}

一些日志可能在 Velocity 启动时有用

velocity - Velocimacro : allowInline = true : VMs can be defined inline in templates
velocity - Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
velocity - Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.

Velocity templates not substituting methods

【问题讨论】:

  • 发生这种行为时comment 的值是多少?您是否在渲染模板之前设置上下文?

标签: java velocity template-engine


【解决方案1】:

尝试这样做:

#if (! $position.getComment() || "$position.getComment()" == "")
    <td class="empty">&mdash;</td>
#else
    <td>$position.getComment()</td>
#end

我是速度方面的新手,所以我无法完全解释为什么,但我已经为一个新项目编写了两个 HTML 模板,在我的团队中,我们发现这种方式是最好的方式去做吧。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 2017-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 2016-05-11
    相关资源
    最近更新 更多