自由标记 - 带点的变量名称
2022-09-03 06:13:42
是否可以在自由标记模板中引用包含点的变量?(或“-”字符)
例如:
主要.java:
public class Main {
public static void main(String[] args) throws IOException, TemplateException {
Configuration freemarkerConfig = new Configuration();
freemarkerConfig.setClassForTemplateLoading(Main.class, "");
Template template = freemarkerConfig.getTemplate("template.ftl");
Map<String, String> data = new HashMap<String, String>();
data.put("variable.name", "value");
Writer out = new StringWriter();
template.process(data, out);
System.out.println(out.toString());
}
}
template.ftl:
${variable.name}
此代码引发异常:
The following has evaluated to null or missing:
==> variable [in template "template.ftl" at line 1, column 3]
是否可以在 tempalte 文件中引用变量“variable.name”?