Freemarker 模板中的 Kotlin 扩展方法
Kotlin Extension Methods in Freemarker Template
给定 Freemarker 模板
class ${name.capitalize()}
和数据
val data = mapOf("name" to "test")
我想通过在 name
上应用扩展方法 capitalize()
来获得以下结果:
class Test
但是,抛出一个错误:
FreeMarker template error:
For "." left-hand operand: Expected a hash, but this has evaluated to a string (wrapper: f.t.SimpleScalar):
==> name [in template "table.ftl" at line 1, column 24]
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${name.capitalize()} [in template "table.ftl" at line 1, column 22]
----
使用 Freemarker 的 capitalize 内置:
class ${name?capitalize}
The string with all words capitalized.
给定 Freemarker 模板
class ${name.capitalize()}
和数据
val data = mapOf("name" to "test")
我想通过在 name
上应用扩展方法 capitalize()
来获得以下结果:
class Test
但是,抛出一个错误:
FreeMarker template error:
For "." left-hand operand: Expected a hash, but this has evaluated to a string (wrapper: f.t.SimpleScalar):
==> name [in template "table.ftl" at line 1, column 24]
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${name.capitalize()} [in template "table.ftl" at line 1, column 22]
----
使用 Freemarker 的 capitalize 内置:
class ${name?capitalize}
The string with all words capitalized.