是否可以在freemarker模板中引用包含点的变量? (或' - '字符)
e.g:
Main.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]
是否可以引用变量&#34; variable.name&#34;在tempalte文件?
答案 0 :(得分:16)
答案 1 :(得分:0)
这是不可能的,因为freemarker会将'name'视为'variable'的属性。所以它首先寻找一个名为'variable'的对象,因为它被命名为'variable.name'