freemarker表达式是否可以包含space
Can freemarker expression contains space
我们有一个场景,比如 Freemarker 表达式的输入数据在变量 ${employee name?} 中包含 spaces 并且低于错误
"Exception in thread "main" freemarker.core.ParseException: Encountered "name" at line 1, column 12 in EMAILTEMPLATES
" 同时应用表达式 .
Freemarker 是否支持自由标记变量中的 space?
Map<Object,Object> out= new HashMap<>();
out.put("employee name", "XXX");
String templateStr="<p> ${employee name?} </p>";
StringWriter out = new StringWriter();
Template emailTemplate = new Template(EMAILTEMPLATES, new
StringReader(templateStr),templateConfiguartion);
emailTemplate.process(dataMap, out);
您可以对特殊变量使用vars:
${.vars["employee name"]}
vars: Expression .vars.foo returns the same variable as expression foo. It's useful if for some reasons you have to use square bracket syntax, since that works only for hash sub variables, so you need an artificial parent hash. For example, to read a top-level variable that has a strange name that would confuse FreeMarker, you can write .vars["A strange name!"].
我们有一个场景,比如 Freemarker 表达式的输入数据在变量 ${employee name?} 中包含 spaces 并且低于错误
"Exception in thread "main" freemarker.core.ParseException: Encountered "name" at line 1, column 12 in EMAILTEMPLATES
" 同时应用表达式 .
Freemarker 是否支持自由标记变量中的 space?
Map<Object,Object> out= new HashMap<>();
out.put("employee name", "XXX");
String templateStr="<p> ${employee name?} </p>";
StringWriter out = new StringWriter();
Template emailTemplate = new Template(EMAILTEMPLATES, new
StringReader(templateStr),templateConfiguartion);
emailTemplate.process(dataMap, out);
您可以对特殊变量使用vars:
${.vars["employee name"]}
vars: Expression .vars.foo returns the same variable as expression foo. It's useful if for some reasons you have to use square bracket syntax, since that works only for hash sub variables, so you need an artificial parent hash. For example, to read a top-level variable that has a strange name that would confuse FreeMarker, you can write .vars["A strange name!"].