异常-----freemarker.template.TemplateException

一,案例一

假如你现在还在为自己的技术担忧,假如你现在想提升自己的工资,假如你想在职场上获得更多的话语权,假如你想顺利的度过35岁这个魔咒,假如你想体验BAT的工作环境,那么现在请我们一起开启提升技术之旅吧,详情请点击http://106.12.206.16:8080/qingruihappy/index.html

1.1、错误描述

  1 五月 30, 2014 11:33:57 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error
  2 严重: Template processing error: "Expected hash. flag evaluated instead to freemarker.template.TemplateBooleanModel$2 on line 21, column 8 in type.ftl."
  3 
  4 Expected hash. flag evaluated instead to freemarker.template.TemplateBooleanModel$2 on line 21, column 8 in type.ftl.
  5 The problematic instruction:
  6 ----------
  7 ==> ${flag.color?string} [on line 21, column 6 in type.ftl]
  8 ----------
  9 
 10 Java backtrace for programmers:
 11 ----------
 12 freemarker.template.TemplateException: Expected hash. flag evaluated instead to freemarker.template.TemplateBooleanModel$2 on line 21, column 8 in type.ftl.
 13     at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
 14     at freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
 15     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 16     at freemarker.core.BuiltIn$stringBI._getAsTemplateModel(BuiltIn.java:408)
 17     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 18     at freemarker.core.Expression.getStringValue(Expression.java:93)
 19     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
 20     at freemarker.core.Environment.visit(Environment.java:221)
 21     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 22     at freemarker.core.Environment.visit(Environment.java:221)
 23     at freemarker.core.Environment.process(Environment.java:199)
 24     at freemarker.template.Template.process(Template.java:259)
 25     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
 26     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:172)
 27     at com.you.test.freemarker.FreemarkerTest.testDataType(FreemarkerTest.java:159)
 28     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 29     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 30     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 31     at java.lang.reflect.Method.invoke(Unknown Source)
 32     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
 33     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 34     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
 35     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 36     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 37     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
 38     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
 39     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
 40     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
 41     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
 42     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
 43     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
 44     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
 45     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
 46     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
 47     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 48     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 49     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 50     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 51     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
 52 
 53 
 54 Expected hash. flag evaluated instead to freemarker.template.TemplateBooleanModel$2 on line 21, column 8 in type.ftl.
 55 The problematic instruction:
 56 ----------
 57 ==> ${flag.color?string} [on line 21, column 6 in type.ftl]
 58 ----------
 59 
 60 Java backtrace for programmers:
 61 ----------
 62 freemarker.template.TemplateException: Expected hash. flag evaluated instead to freemarker.template.TemplateBooleanModel$2 on line 21, column 8 in type.ftl.
 63     at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
 64     at freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
 65     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 66     at freemarker.core.BuiltIn$stringBI._getAsTemplateModel(BuiltIn.java:408)
 67     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 68     at freemarker.core.Expression.getStringValue(Expression.java:93)
 69     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
 70     at freemarker.core.Environment.visit(Environment.java:221)
 71     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 72     at freemarker.core.Environment.visit(Environment.java:221)
 73     at freemarker.core.Environment.process(Environment.java:199)
 74     at freemarker.template.Template.process(Template.java:259)
 75     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
 76     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:172)
 77     at com.you.test.freemarker.FreemarkerTest.testDataType(FreemarkerTest.java:159)
 78     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 79     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 80     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 81     at java.lang.reflect.Method.invoke(Unknown Source)
 82     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
 83     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 84     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
 85     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 86     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 87     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
 88     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
 89     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
 90     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
 91     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
 92     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
 93     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
 94     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
 95     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
 96     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
 97     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 98 <html>
 99   <head>
100     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
101     <title>freemarker基本数据类型</title>
102 
103   </head>
104   
105   <body>
106           张三丰
107      
108      123,456
109      
110      true
111      
112 Expected hash. flag evaluated instead to freemarker.template.TemplateBooleanModel$2 on line 21, column 8 in type.ftl.
113 The problematic instruction:
114 ----------
115 ==> ${flag.color?string} [on line 21, column 6 in type.ftl]
116 ----------
117 
118 Java backtrace for programmers:
119 ----------
120 freemarker.template.TemplateException: Expected hash. flag evaluated instead to freemarker.template.TemplateBooleanModel$2 on line 21, column 8 in type.ftl.
121     at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
122     at freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
123     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
124     at freemarker.core.BuiltIn$stringBI._getAsTemplateModel(BuiltIn.java:408)
125     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
126     at freemarker.core.Expression.getStringValue(Expression.java:93)
127     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
128     at freemarker.core.Environment.visit(Environment.java:221)
129     at freemarker.core.MixedContent.accept(MixedContent.java:92)
130     at freemarker.core.Environment.visit(Environment.java:221)
131     at freemarker.core.Environment.process(Environment.java:199)
132     at freemarker.template.Template.process(Template.java:259)
133     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
134     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:172)
135     at com.you.test.freemarker.FreemarkerTest.testDataType(FreemarkerTest.java:159)
136     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
137     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
138     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
139     at java.lang.reflect.Method.invoke(Unknown Source)
140     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
141     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
142     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
143     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
144     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
145     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
146     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
147     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
148     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
149     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
150     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
151     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
152     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
153     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
154     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
155     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
156     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
157     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
158     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
159     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
160     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
161     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
162     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
163     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 

 1.2、错误原因

1 <#--定义布尔值-->
2 <#assign flag = true/>
3 ${flag?string}
4 ${flag.color?string}

    因为flag已经定义为true,再次定义会报错

 

1.3、解决办法

     修改变量名,将flag修改为num

1 ${(num.color)???string}

结果:false

 

 二,案例二

2.1、错误描述

  1 六月 04, 2014 10:31:47 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error
  2 严重: Template processing error: "Expected number, sequence, or string. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 11, column 12 in map.ftl."
  3 
  4 Expected number, sequence, or string. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 11, column 12 in map.ftl.
  5 The problematic instruction:
  6 ----------
  7 ==> ${maps[3]} [on line 11, column 10 in map.ftl]
  8 ----------
  9 
 10 Java backtrace for programmers:
 11 ----------
 12 freemarker.template.TemplateException: Expected number, sequence, or string. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 11, column 12 in map.ftl.
 13     at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
 14     at freemarker.core.DynamicKeyName.dealWithNumericalKey(DynamicKeyName.java:125)
 15     at freemarker.core.DynamicKeyName._getAsTemplateModel(DynamicKeyName.java:90)
 16     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 17     at freemarker.core.Expression.getStringValue(Expression.java:93)
 18     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
 19     at freemarker.core.Environment.visit(Environment.java:221)
 20     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 21     at freemarker.core.Environment.visit(Environment.java:221)
 22     at freemarker.core.Environment.process(Environment.java:199)
 23     at freemarker.template.Template.process(Template.java:259)
 24     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
 25     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
 26     at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
 27     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 28     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 29     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 30     at java.lang.reflect.Method.invoke(Unknown Source)
 31     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
 32     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 33     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
 34     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 35     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 36     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
 37     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
 38     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
 39     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
 40     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
 41     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
 42     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
 43     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
 44     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
 45     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
 46     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 47     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 48     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 49     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 50     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
 51 
 52 <html>
 53   <head>
 54     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 55     <title>freemarker</title>
 56 
 57   </head>
 58   
 59   <body>
 60           
 61 Expected number, sequence, or string. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 11, column 12 in map.ftl.
 62 The problematic instruction:
 63 ----------
 64 ==> ${maps[3]} [on line 11, column 10 in map.ftl]
 65 ----------
 66 
 67 Java backtrace for programmers:
 68 ----------
 69 freemarker.template.TemplateException: Expected number, sequence, or string. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 11, column 12 in map.ftl.
 70     at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
 71     at freemarker.core.DynamicKeyName.dealWithNumericalKey(DynamicKeyName.java:125)
 72     at freemarker.core.DynamicKeyName._getAsTemplateModel(DynamicKeyName.java:90)
 73     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 74     at freemarker.core.Expression.getStringValue(Expression.java:93)
 75     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
 76     at freemarker.core.Environment.visit(Environment.java:221)
 77     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 78     at freemarker.core.Environment.visit(Environment.java:221)
 79     at freemarker.core.Environment.process(Environment.java:199)
 80     at freemarker.template.Template.process(Template.java:259)
 81     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
 82     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
 83     at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
 84     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 85     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 86     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 87     at java.lang.reflect.Method.invoke(Unknown Source)
 88     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
 89     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 90     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
 91     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 92     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 93     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
 94     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
 95     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
 96     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
 97     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
 98     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
 99     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
100     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
101     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
102     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
103     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
104     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
105     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
106     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
107     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
108 
109 Expected number, sequence, or string. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 11, column 12 in map.ftl.
110 The problematic instruction:
111 ----------
112 ==> ${maps[3]} [on line 11, column 10 in map.ftl]
113 ----------
114 
115 Java backtrace for programmers:
116 ----------
117 freemarker.template.TemplateException: Expected number, sequence, or string. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 11, column 12 in map.ftl.
118     at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
119     at freemarker.core.DynamicKeyName.dealWithNumericalKey(DynamicKeyName.java:125)
120     at freemarker.core.DynamicKeyName._getAsTemplateModel(DynamicKeyName.java:90)
121     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
122     at freemarker.core.Expression.getStringValue(Expression.java:93)
123     at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
124     at freemarker.core.Environment.visit(Environment.java:221)
125     at freemarker.core.MixedContent.accept(MixedContent.java:92)
126     at freemarker.core.Environment.visit(Environment.java:221)
127     at freemarker.core.Environment.process(Environment.java:199)
128     at freemarker.template.Template.process(Template.java:259)
129     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
130     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
131     at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
132     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
133     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
134     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
135     at java.lang.reflect.Method.invoke(Unknown Source)
136     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
137     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
138     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
139     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
140     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
141     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
142     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
143     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
144     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
145     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
146     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
147     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
148     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
149     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
150     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
151     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
152     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
153     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
154     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
155     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

2.2、错误原因

1 <#--freemarker HashMap取值-->
2 <#assign maps={"1":"张三丰","2":"李思思","3":"张三强","4":"王五"}/>
3 ${maps[3]}

map取值时是要取序列、数字、字符串

2.3,解决办法

    ${maps["3"]}

 

 三,案例三

3.1,错误描述

  1 <html>
  2   <head>
  3     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  4     <title>freemarker处理哈希表的内建函数</title>
  5 
  6   </head>
  7   
  8   <body>
  9           张三强
 10      
 11 
 12 Expected collection or sequence. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 13, column 17 in map.ftl.
 13 The problematic instruction:
 14 ----------
 15 ==> list maps as map [on line 13, column 10 in map.ftl]
 16 ----------
 17 
 18 Java backtrace for programmers:
 19 ----------
 20 freemarker.template.TemplateException: Expected collection or sequence. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 13, column 17 in map.ftl.
 21     at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
 22     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:190)
 23     at freemarker.core.Environment.visit(Environment.java:428)
 24     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
 25     at freemarker.core.Environment.visit(Environment.java:221)
 26     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 27     at freemarker.core.Environment.visit(Environment.java:221)
 28     at freemarker.core.Environment.process(Environment.java:199)
 29     at freemarker.template.Template.process(Template.java:259)
 30     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
 31     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
 32     at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
 33     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 34     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 35     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 36     at java.lang.reflect.Method.invoke(Unknown Source)
 37     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
 38     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 39     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
 40     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 41     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 42     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
 43     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
 44     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
 45     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
 46     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
 47     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
 48     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
 49     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
 50     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
 51     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
 52     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 53     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 54     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 55     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 56     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
 57 六月 04, 2014 10:52:14 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error
 58 严重: Template processing error: "Expected collection or sequence. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 13, column 17 in map.ftl."
 59 
 60 Expected collection or sequence. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 13, column 17 in map.ftl.
 61 The problematic instruction:
 62 ----------
 63 ==> list maps as map [on line 13, column 10 in map.ftl]
 64 ----------
 65 
 66 Java backtrace for programmers:
 67 ----------
 68 freemarker.template.TemplateException: Expected collection or sequence. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 13, column 17 in map.ftl.
 69     at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
 70     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:190)
 71     at freemarker.core.Environment.visit(Environment.java:428)
 72     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
 73     at freemarker.core.Environment.visit(Environment.java:221)
 74     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 75     at freemarker.core.Environment.visit(Environment.java:221)
 76     at freemarker.core.Environment.process(Environment.java:199)
 77     at freemarker.template.Template.process(Template.java:259)
 78     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
 79     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
 80     at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
 81     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 82     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 83     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 84     at java.lang.reflect.Method.invoke(Unknown Source)
 85     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
 86     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 87     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
 88     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 89     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 90     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
 91     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
 92     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
 93     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
 94     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
 95     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
 96     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
 97     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
 98     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
 99     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
100     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
101     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
102     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
103     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
104     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
105 
106 
107 Expected collection or sequence. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 13, column 17 in map.ftl.
108 The problematic instruction:
109 ----------
110 ==> list maps as map [on line 13, column 10 in map.ftl]
111 ----------
112 
113 Java backtrace for programmers:
114 ----------
115 freemarker.template.TemplateException: Expected collection or sequence. maps evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 13, column 17 in map.ftl.
116     at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
117     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:190)
118     at freemarker.core.Environment.visit(Environment.java:428)
119     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
120     at freemarker.core.Environment.visit(Environment.java:221)
121     at freemarker.core.MixedContent.accept(MixedContent.java:92)
122     at freemarker.core.Environment.visit(Environment.java:221)
123     at freemarker.core.Environment.process(Environment.java:199)
124     at freemarker.template.Template.process(Template.java:259)
125     at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:77)
126     at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
127     at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
128     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
129     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
130     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
131     at java.lang.reflect.Method.invoke(Unknown Source)
132     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
133     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
134     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
135     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
136     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
137     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
138     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
139     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
140     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
141     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
142     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
143     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
144     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
145     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
146     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
147     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
148     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
149     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
150     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
151     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 

3.2,错误原因 

maps不是一个序列,不能用list遍历map

1  <#--freemarker HashMap取值-->
2 <#assign maps={"1":"张三丰","2":"李思思","3":"张三强","4":"王五"}>
3 ${maps["3"]}
4      
5 <#list maps as map>
6  ${map}
7 </#list>

3.3、解决办法

 

    先获取map中的key值,再通过key值序列遍历map

 

1 <#--freemarker HashMap取值-->
2      <#assign maps={"1":"张三丰","2":"李思思","3":"张三强","4":"王五"}>
3      ${maps["3"]}
4      
5      <#assign keys=maps?keys>
6      <#list keys as key>
7         ${key}----${maps[key]}
8      </#list>

 

假如你现在还在为自己的技术担忧,假如你现在想提升自己的工资,假如你想在职场上获得更多的话语权,假如你想顺利的度过35岁这个魔咒,假如你想体验BAT的工作环境,那么现在请我们一起开启提升技术之旅吧,详情请点击http://106.12.206.16:8080/qingruihappy/index.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值