java - 如何将此行从 Velocity 转换为 FreeMarker?

标签 java velocity freemarker

我想将此行从 Velocity 转换为 Freemarker:

#set ($valid_portlet_description = $validator.isNotNull($portlet_description) 
&& $portlet_description.indexOf('javax.portlet.description') == -1)

我尝试将代码更改为:

<#assign valid_portlet_description = validator.isNotNull(portlet_description) 
&& portlet_description?index_of("javax.portlet.description") == "-1" />

但是我收到以下错误:

freemarker.template.TemplateException: The only legal comparisons are between two numbers, two strings, or two dates. Left hand operand is a freemarker.template.SimpleNumber Right hand operand is a freemarker.template.SimpleScalar

最佳答案

该消息提示此声明:

portlet_description?index_of("javax.portlet.description") == "-1"

它表示您有不同的类型:数字在左侧,但 SimpleScalar (在 Freemarker 术语中只是 String)在右侧。要解决此问题,您只需删除引号即可:

portlet_description?index_of("javax.portlet.description") == -1

关于java - 如何将此行从 Velocity 转换为 FreeMarker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33890672/

相关文章:

java - 错误 org.apache.velocity : ResourceManager : unable to find resource 'xxx.html.vm' in any resource loader

java - 将列表从 Java 返回到 Freemarker

javascript - 在 Freemarker 模板中的 Javascript 中运行 Java 方法

java - 使用 notifyDataSetChanged() 时,Android API ListView 不会更新;

java - Coldfusion.security.NTAuthentication : Error in locating groups for user XXX in domain XXX

java - Spring 和 Hibernate - 通用实体更新

java - 在 Java 中,在发送 JSON POST 时使用 HttpPost(apache commons HttpClient)——我应该对正文进行 URL 编码吗?

apache - Velocity 找不到资源

java - 速度:#if、#else 和 #end 之前或之后的空格?

java - ftl 模板中的 escapeHtml ="false"引发参数类型不匹配