我尝试使用 FreeMarker 创建html file
.
但是当我运行程序时它会抛出错误:
Error reading included file "./common/header.ftl":
Template "./common/header.ftl" not found.
The failing instruction:
==> #include "./common/header.ftl" [in template "helloworld.ftl" at line 1, column 1]
helloworld.ftl:
<#include "./common/header.ftl">
<#if container??>
<div ="${container}">
<#else>
<div ="default">
</#if>
<ul>
<#list systems as system>
<li>${system_index + 1}.${system.getName()}</li>
</#list>
</ul>
<h1>${exampleObject.getName()}</h1>
</div>
<#include "./common/footer.ftl">
代码片段:
public static void main(String[] args) {
// Configuration
Writer file = null;
Configuration cfg = new Configuration();
try {
// Set Directory for templates
cfg.setDirectoryForTemplateLoading(new File("templates"));
// load template
Template template = cfg.getTemplate("helloworld.ftl");
// data-model
Map<String, Object> input = new HashMap<String, Object>();
input.put("message", "vogella example");
input.put("container", "test");
// create list
List<ValueExampleObject> systems = new ArrayList<ValueExampleObject>();
内部文件header.ftl
和footer.ftl
进入template/common
(进入template
正是 helloworld.ftl 和常见的)。
- 为什么会这样?
- 如何解决这个问题?