本文为配置ftl模板路径提供了相对路径和绝对路径两种方法,具体如何生成word请看博主的另一篇文章
配置文件
# 配置freemarker
freemarker:
allow-request-override: false
#开发过程建议关闭缓存
cache: false
check-template-location: false
charset: UTF-8
content-type: text/html; charset=utf-8
expose-request-attributes: false
expose-session-attributes: false
expose-spring-macro-helpers: false
request-context-attribute:
# 默认后缀就是.ftl
suffix: .ftl
# ftl模板位置
# 绝对路径
template-loader-path: F:\test
# 相对路径
# template-loader-path: classPath:/templates/
源码
Configuration configuration = new Configuration(VERSION_2_3_0);
configuration.setDefaultEncoding("utf-8");
//相对路径加载模板方法
//configuration.setClassForTemplateLoading(this.getClass(), templateLoaderPath);
//绝对路径加载模板方法
FileTemplateLoader fileTemplateLoader=new FileTemplateLoader(new File(templateLoaderPath));
configuration.setTemplateLoader(fileTemplateLoader);
Template template = configuration.getTemplate(templeName+suffix);