一,案例一
1.1、错误描述
1 freemarker.core.ParseException: Token manager error: freemarker.core.TokenMgrError: Lexical error at line 16, column 50. Encountered: "\uff01" (65281), after : "" in course.ftl
2 at freemarker.template.Template.(Template.java:174)
3 at freemarker.cache.TemplateCache.loadTemplate(TemplateCache.java:447)
4 at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:360)
5 at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:235)
6 at freemarker.template.Configuration.getTemplate(Configuration.java:578)
7 at freemarker.template.Configuration.getTemplate(Configuration.java:543)
8 at com.you.freemarker.FreemarkerTemplate.getTemplate(FreemarkerTemplate.java:52)
9 at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:76)
10 at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:142)
11 at com.you.test.freemarker.FreemarkerTest.testCourse(FreemarkerTest.java:129)
12 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
13 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
14 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
15 at java.lang.reflect.Method.invoke(Unknown Source)
16 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
17 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
18 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
19 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
20 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
21 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
22 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
23 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
24 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
25 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
26 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
27 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
28 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
29 at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
30 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
31 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
32 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
33 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
34 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
35 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
1.2、错误原因
"没有任何值存在"前多了一个空格
1 ${(student.course.courseName)!"没有任何值存在"}
1.3、解决办法
"没有任何值存在"前面的空格去掉
1 ${(student.course.courseName)!"没有任何值存在"}
二,案例二
2.1,错误描述
1 freemarker.core.ParseException: Token manager error: freemarker.core.TokenMgrError: Unknown directive: #list on line: 17, column: 61, in template: map.ftl in map.ftl
2 at freemarker.template.Template.(Template.java:174)
3 at freemarker.cache.TemplateCache.loadTemplate(TemplateCache.java:447)
4 at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:360)
5 at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:235)
6 at freemarker.template.Configuration.getTemplate(Configuration.java:578)
7 at freemarker.template.Configuration.getTemplate(Configuration.java:543)
8 at com.you.freemarker.FreemarkerTemplate.getTemplate(FreemarkerTemplate.java:52)
9 at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:76)
10 at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:210)
11 at com.you.test.freemarker.FreemarkerTest.testMap(FreemarkerTest.java:197)
12 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
13 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
14 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
15 at java.lang.reflect.Method.invoke(Unknown Source)
16 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
17 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
18 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
19 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
20 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
21 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
22 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
23 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
24 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
25 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
26 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
27 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
28 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
29 at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
30 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
31 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
32 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
33 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
34 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
35 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
2.2,错误原因
结束标签书写不对
1 <#assign stu={"name":"zhangsan","age":"21","sex":"man"}>
2 <#assign keys = stu?keys>
3 <#list keys as key>
4 ${key} = ${stu[key]};
5 <#list>
2.3,解决办法
正确写结束标签
1 <#assign stu={"name":"zhangsan","age":"21","sex":"man"}>
2 <#assign keys = stu?keys>
3 <#list keys as key>
4 ${key} = ${stu[key]};
5 #list>
就是不是<#list>而是#list>
三,案例三
freemarker自定义标签
3.1、错误描述
1 freemarker.core.ParseException: Token manager error: freemarker.core.TokenMgrError: Unknown directive: #macro on line: 12, column: 101, in template: myself.ftl in myself.ftl
2 at freemarker.template.Template.(Template.java:174)
3 at freemarker.cache.TemplateCache.loadTemplate(TemplateCache.java:447)
4 at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:360)
5 at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:235)
6 at freemarker.template.Configuration.getTemplate(Configuration.java:578)
7 at freemarker.template.Configuration.getTemplate(Configuration.java:543)
8 at com.you.freemarker.FreemarkerTemplate.getTemplate(FreemarkerTemplate.java:52)
9 at com.you.freemarker.FreemarkerTemplate.printFtl(FreemarkerTemplate.java:76)
10 at com.you.test.freemarker.FreemarkerTest.studentPrint(FreemarkerTest.java:217)
11 at com.you.test.freemarker.FreemarkerTest.testMyself(FreemarkerTest.java:204)
12 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
13 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
14 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
15 at java.lang.reflect.Method.invoke(Unknown Source)
16 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
17 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
18 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
19 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
20 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
21 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
22 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
23 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
24 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
25 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
26 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
27 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
28 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
29 at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
30 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
31 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
32 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
33 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
34 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
35 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
3.2,错误原因
1 <#--freemarker自定义标签-->
2 <#macro write>
3 ${repeat("张三丰",3)}
4 <#macro>
3.3、解决办法
又犯了同样的错误,结束标签没有封口
1 <#--freemarker自定义标签-->
2 <#macro write>
3 ${repeat("张三丰",3)}
4 #macro>
转自:https://www.cnblogs.com/qingruihappy/p/7874595.html