SpringBoot 配置 freemarker

1 yml 文件:

spring:
  freemarker:
    suffix: .ftl
    templateEncoding: UTF-8
    templateLoaderPath: classpath:/templates/
    charset: UTF-8
    content-type: text/html;charset=UTF-8
    default_encoding: UTF-8
    cache: false
    expose-session-attributes: true
    # 设置上下文路径
    request-context-attribute: request 


2 maven依赖



        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-freemarkerartifactId>
        dependency>

3 获取上下文路径

页面获取方式: r e q u e s t . c o n t e x t P a t h < l i n k r e l = " s t y l e s h e e t " h r e f = " {request.contextPath} <link rel="stylesheet" href=" request.contextPath<linkrel="stylesheet"href="{request.contextPath}/css.css"/>

以上无法获取到,试试下面

<#assign ctx=request.contextPath />

这样后来发现也无法获取到 值为null
然后百度 发现这样子可以:

<#assign ctx=springMacroRequestContext.contextPath />

然后
${ctx} 即可

你可能感兴趣的:(springboot)