我试图让 Freemarker 将我的模板文件解析为 UTF-8,但它似乎总是将它们解析为 Cp1252。
2013-07-30 00:00:00.984 DEBUG freemarker.cache:? Could not find template in cache, creating new one; id=["myFile.ftl"["es_MX",Cp1252,parsed] ]
我搜索并发现添加 FTL 指令可以让我指定编码。
我将它添加到模板文件中(使用 Notepad++ 中的 BOM 保存在 UTF-8 中),如下所示:
<#ftl encoding="UTF-8">
Estimado Usuario,
Testing this content!
<#/ftl>
但是在日志中得到这个。
MessageTemplateException [message=Unable to process template due to Encountered "<#ftl " at line 1, column 4 in myFile.ftl.
Was expecting one of:
<EOF>
<ATTEMPT> ...
<IF> ...
<LIST> ...
<FOREACH> ...
<SWITCH> ...
<ASSIGN> ...
<GLOBALASSIGN> ...
<LOCALASSIGN> ...
<_INCLUDE> ...
<IMPORT> ...
<FUNCTION> ...
<MACRO> ...
<TRANSFORM> ...
<VISIT> ...
<STOP> ...
<RETURN> ...
<CALL> ...
<SETTING> ...
<COMPRESS> ...
<COMMENT> ...
<TERSE_COMMENT> ...
<NOPARSE> ...
<BREAK> ...
<SIMPLE_RETURN> ...
<HALT> ...
<FLUSH> ...
<TRIM> ...
<LTRIM> ...
<RTRIM> ...
<NOTRIM> ...
<SIMPLE_NESTED> ...
<NESTED> ...
<SIMPLE_RECURSE> ...
<RECURSE> ...
<FALLBACK> ...
<ESCAPE> ...
<NOESCAPE> ...
<UNIFIED_CALL> ...
<WHITESPACE> ...
<PRINTABLE_CHARS> ...
<FALSE_ALERT> ...
"${" ...
"#{" ...
with inputs of {loginUrl=testURL} in myFile.ftl with locale es_MX, code=SUCCESS, arguments=[]]
也许我做的不对?