我有一个freemarker模板,我想编写一个测试来检查给定模型输入的输出。
@Test
public void testProcessTemplateWithModel() throws Exception {
final Configuration configuration = new Configuration();
configuration.setDirectoryForTemplateLoading(directoryForTemplateLoading);
configuration.setObjectWrapper(new DefaultObjectWrapper());
final Template template = configuration.getTemplate("template.ftl");
final Map<String, Object> model = new HashMap<String, Object>();
/* populate model */
template.process(model, new OutputStreamWriter(System.out));
}
麻烦的是模板中的第一行是:
<#import "spring.ftl" as spring />
所以我得到了:
ERROR [main] freemarker.runtime - Error reading imported file spring.ftl
Error reading imported file spring.ftl
The problematic instruction:
----------
==> import "spring.ftl" as spring [on line 1, column 1 in template.ftl]
----------
在模板上设置导入似乎是不可能的。