Freemarker模板中的Kotlin扩展方法

时间:2019-02-13 13:18:53

标签: kotlin freemarker capitalization

给出Freemarker模板

class ${name.capitalize()}

和数据

val data = mapOf("name" to "test")

我想通过在capitalize()上应用扩展方法name得到以下结果:

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]
----

1 个答案:

答案 0 :(得分:1)

使用内置的Freemarker的capitalize

class ${name?capitalize}
  

所有单词都大写的字符串。