springboot中freemarker怎么加载模板


在Spring Boot应用中加载Freemarker模板需要进行以下步骤:

    首先需要在pom.xml文件中添加Freemarker依赖:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency>

    创建Freemarker模板文件,通常会存放在src/main/resources/templates目录下。

    在Spring Boot应用中创建一个Controller类,用于处理请求并返回Freemarker模板:

import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;@Controllerpublic class HomeController {@GetMapping("/")public String home() {return "index"; // 返回模板文件名,不需要加后缀}}
    application.propertiesapplication.yml文件中配置Freemarker相关的属性,如模板文件的存放路径等。例如,在application.properties中添加以下配置:
spring.freemarker.template-loader-path=classpath:/templates/spring.freemarker.suffix=.ftl
    启动Spring Boot应用后,访问对应的URL即可加载并显示Freemarker模板。

注意:以上示例中的模板文件名为index.ftl,实际使用时可以根据需要创建不同的模板文件,并在Controller中返回对应的模板文件名。


上一篇:c++中strncpy函数的功能有哪些

下一篇:Apriori怎么计算一个项集的支持度


SpringBoot
Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器