Apache Velocity Quiet Reference Notation 作为默认行为
当 Velocity 遇到未定义的参考时,其正常行为是输出参考的图像。例如,假设以下引用作为 VTL 模板的一部分出现”示例:
<input type="text" name="email" value="$!email"/>
是否可以配置默认行为,以便我仍然可以编写 $email
并且它隐式是一个安静的表示法?
When Velocity encounters an undefined reference, its normal behavior is to output the image of the reference. For example, suppose the following reference appears as part of a VTL template" example:
<input type="text" name="email" value="$!email"/>
Is it possible to configure a default behaviour, so that I could still write $email
and it's implicitly a quiet notation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。当发现无效引用时,会调用一个事件处理程序。它称为 InvalidReferenceEventHandler。您需要让事件处理程序返回一个空字符串。
有关如何创建和注册事件处理程序的详细信息,请参阅 Velocity 开发人员指南。但简而言之,实现 InvalidReferenceEventHandler,然后在设置 VelocityEngine 时包含此属性。
Yes. There's an event handler which is called when an invalid reference is found. It's called InvalidReferenceEventHandler. You'll want to have the event handler return an empty string.
Consult the Velocity Developer's Guide for details on how to create and register an event handler. But in a nutshell, implement InvalidReferenceEventHandler and then include this property when setting up your VelocityEngine.