允许 Apache 的 FreeMarker 模板引擎从外部资源文件夹加载模板答案

您所在的位置:网站首页 springfreemarker 允许 Apache 的 FreeMarker 模板引擎从外部资源文件夹加载模板答案

允许 Apache 的 FreeMarker 模板引擎从外部资源文件夹加载模板答案

#允许 Apache 的 FreeMarker 模板引擎从外部资源文件夹加载模板答案| 来源: 网络整理| 查看: 265

我使用 Spring Initilizr 创建了一个 Spring Boot 应用程序。然后我包含了Apache's Freemarker 模板引擎来从我的项目中加载模板。默认情况下,引擎从以下位置加载模板:src/main/resources/templates/ 文件夹。

当用户访问网页http://localhost:8080 时,我正在尝试加载一个简单的index.ftl 文件作为模板。但我需要从src/main/webapp/ 文件夹加载模板。每当我尝试从 resources 文件夹外部加载模板时,模板引擎都无法找到模板。

我已经阅读了各种教程和 Stack Overflow 问题。没有人回答我的问题,我被 404 ERROR 卡住了,因为引擎无法找到文件。

文件结构为:

|-src |---main |-----java |-------MainApplication.java |-------controllers |---------ViewController.java |-----resources |-------static |-------templates |-------application.properties |-----webapp |-------index.ftl

经过大量挖掘,我发现了一篇帖子,他们建议更改模板引擎搜索文件的位置。它建议在 application.properties 中添加以下行:

spring.freemarker.enabled=true spring.freemarker.template-loader-path=classpath:src/main/webapp/

这似乎根本不起作用。

当我访问http://localhost:8080 的网页时,我正在尝试解析简单的索引页面。我编写了以下代码来映射ViewController.java 中的 HTTP 请求:

@RequestMapping("/") public ModelAndView home(Model model) { return new ModelAndView("index"); }

不知道是我完全弄错了还是我错过了一些配置。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3