在网上找到了尚学堂的视频,同时有书和源码等资料。但是在跟着练习的过程中,代码运行报了错:
2015-7-20 22:26:40 freemarker.log.JDK14LoggerFactory$JDK14Logger error
严重:
Don't know how to present an object of this type to a template: com.sxt.test.freemarker.Address
Quoting problematic instruction:
----------
==> list lst as dizhi [on line 3, column 1 in a.ftl]
----------
Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Don't know how to present an object of this type to a template: com.sxt.test.freemarker.Address
at freemarker.template.SimpleObjectWrapper.handleUnknownType(SimpleObjectWrapper.java:139)
at freemarker.template.SimpleObjectWrapper.wrap(SimpleObjectWrapper.java:116)
at freemarker.template.WrappingTemplateModel.wrap(WrappingTemplateModel.java:131)
at freemarker.template.SimpleSequence.get(SimpleSequence.java:197)
at freemarker.template.IteratorBlock$Context.runLoop(IteratorBlock.java:163)
at freemarker.template.Environment.visit(Environment.java:316)
at freemarker.template.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.template.Environment.visit(Environment.java:180)
at freemarker.template.MixedContent.accept(MixedContent.java:91)
at freemarker.template.Environment.visit(Environment.java:180)
at freemarker.template.Environment.process(Environment.java:166)
at freemarker.template.Template.process(Template.java:238)
at com.sxt.test.freemarker.Test1.main(Test1.java:26)
Exception in thread "main"
Don't know how to present an object of this type to a template: com.sxt.test.freemarker.Address
Quoting problematic instruction:
----------
==> list lst as dizhi [on line 3, column 1 in a.ftl]
----------
Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Don't know how to present an object of this type to a template: com.sxt.test.freemarker.Address
at freemarker.template.SimpleObjectWrapper.handleUnknownType(SimpleObjectWrapper.java:139)
at freemarker.template.SimpleObjectWrapper.wrap(SimpleObjectWrapper.java:116)
at freemarker.template.WrappingTemplateModel.wrap(WrappingTemplateModel.java:131)
at freemarker.template.SimpleSequence.get(SimpleSequence.java:197)
at freemarker.template.IteratorBlock$Context.runLoop(IteratorBlock.java:163)
at freemarker.template.Environment.visit(Environment.java:316)
at freemarker.template.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.template.Environment.visit(Environment.java:180)
at freemarker.template.MixedContent.accept(MixedContent.java:91)
at freemarker.template.Environment.visit(Environment.java:180)
at freemarker.template.Environment.process(Environment.java:166)
at freemarker.template.Template.process(Template.java:238)
at com.sxt.test.freemarker.Test1.main(Test1.java:26)
你好!你需要不断地学习,不停的努力 !
Don't know how to present an object of this type to a template: com.sxt.test.freemarker.Address
Quoting problematic instruction:
----------
==> list lst as dizhi [on line 3, column 1 in a.ftl]
----------
Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Don't know how to present an object of this type to a template: com.sxt.test.freemarker.Address
at freemarker.template.SimpleObjectWrapper.handleUnknownType(SimpleObjectWrapper.java:139)
at freemarker.template.SimpleObjectWrapper.wrap(SimpleObjectWrapper.java:116)
at freemarker.template.WrappingTemplateModel.wrap(WrappingTemplateModel.java:131)
at freemarker.template.SimpleSequence.get(SimpleSequence.java:197)
at freemarker.template.IteratorBlock$Context.runLoop(IteratorBlock.java:163)
at freemarker.template.Environment.visit(Environment.java:316)
at freemarker.template.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.template.Environment.visit(Environment.java:180)
at freemarker.template.MixedContent.accept(MixedContent.java:91)
at freemarker.template.Environment.visit(Environment.java:180)
at freemarker.template.Environment.process(Environment.java:166)
at freemarker.template.Template.process(Template.java:238)
at com.sxt.test.freemarker.Test1.main(Test1.java:26)
原因是freemarker.jar 版本所致,换成高版本的就行了。(百度网盘上尚学堂提供了两个版本的jar文件)。
快十一点了,该休息了。加油,让今天成为生命中最美好的一天 !