springboot freemark linux 找不到ftl文件

文件路径:

 

 

再idea中这样写是可以正常导出文件,但是 打成jar放到linux上就找不到文件了。

String templatePath =WordUtils.class.getResource("/").getPath()+ "/ftl";
cfg.setDirectoryForTemplateLoading(new File(templatePath));

修改为:

    cfg.setTemplateLoader(new ClassTemplateLoader(
            new WordUtils().getClass().getClassLoader(),  "/ftl"));

 

posted @ 2020-06-05 15:08  木枝木枝  阅读(995)  评论(0编辑  收藏  举报