我有以下HashMap:
Map<String, Object> hashMap = new HashMap<>();
hashMap.put("type", "message");
我在freemarker模板中写了一个switch语句:
<#switch hashMap.get("type")>
<#case "message">
<p>Message type</p>
<#default>
<p>Nothing</p>
</#switch>
但是当我执行代码时,我会遇到异常:
freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134)
at freemarker.core.UnexpectedTypeException.newDesciptionBuilder(UnexpectedTypeException.java:80)
at freemarker.core.UnexpectedTypeException.<init>(UnexpectedTypeException.java:43)
at freemarker.core.NonHashException.<init>(NonHashException.java:49)
at freemarker.core.Dot._eval(Dot.java:48)
at freemarker.core.Expression.eval(Expression.java:81)
at freemarker.core.MethodCall._eval(MethodCall.java:58)
at freemarker.core.Expression.eval(Expression.java:81)
at freemarker.core.EvalUtil.compare(EvalUtil.java:111)
at freemarker.core.SwitchBlock.accept(SwitchBlock.java:67)
at freemarker.core.Environment.visit(Environment.java:326)
at freemarker.core.Environment.visit(Environment.java:332)
at freemarker.core.Environment.process(Environment.java:305)
at freemarker.template.Template.process(Template.java:378)
at com.comp.www.reports.FreeMarkerReport.main(FreeMarkerReport.java:70)
任何人都可以指出我做错了什么吗?
答案 0 :(得分:2)
而不是
hashMap[type]
使用
$('#origVal').keyup(function () {
myVar = $('#origVal').val();
window["window_myVar"] = myVar;
});
console.log(window["window_myVar"]);