springboot集成freemarker模板引擎

本文介绍了如何在SpringBoot项目中集成Freemarker模板引擎,包括添加依赖、配置application.yml、创建类以获取SpringBean以及启动类的修改。同时,文章还讨论了在使用Bootstrap框架时遇到的字体图标显示问题,由于Maven过滤器解析导致字体文件损坏,浏览器无法正确解析。为解决这个问题,作者尝试了将静态资源目录全量引入,并分享了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

添加依赖

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

配置application.yml

spring:
  freemarker:
    # 设定模板的加载路径,多个以逗号分隔,默认:
    tempalte-loader-path:
      classpath: /templates
    # 是否启用模板缓存
    cache: false
    charset: utf-8
    # 设定模板的后缀
    suffix: .ftl

创建类(可以在普通类中获取到springbean)

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringContextHolder implements ApplicationContextAware {

    private static A
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值