2019 - SpringBoot IDEA 配置 Freemarker 模板

一、创建目录

二、设置 ftl 文件模板

三、创建 ftl 文件

四、配置 application.yml

五、访问及跳转

1. 创建 success.ftl

2. 创建一个 Controller 控制器

3. 访问 localhost:8080/success


一、创建目录

2019 - SpringBoot IDEA 配置 Freemarker 模板_第1张图片

二、设置 ftl 文件模板

2019 - SpringBoot IDEA 配置 Freemarker 模板_第2张图片

<#--
  Created by IntelliJ IDEA.
  User: ${USER}
  Date: ${DATE}
  Time: ${TIME}
  To change this template use File | Settings | File Templates.
-->



  
  #[[$Title$]]#


#[[$END$]]#

三、创建 ftl 文件

2019 - SpringBoot IDEA 配置 Freemarker 模板_第3张图片

输入文件名即可。

四、配置 application.yml

# Spring的配置
spring:
  # 模板配置
  profiles: default
  freemarker:
    template-loader-path: classpath:/templates/views/ftl/
    cache: true
    check-template-location: true
    content-type: text/html; charset=UTF-8
    expose-request-attributes: true
    expose-session-attributes: true
    request-context-attribute: request
    suffix: .ftl

五、访问及跳转

默认访问的是 index.ftl

1. 创建 success.ftl

2019 - SpringBoot IDEA 配置 Freemarker 模板_第4张图片




    
    欢迎



    

哈哈success

2. 创建一个 Controller 控制器

public class Index {

    @RequestMapping("success")
    public String Index() {
        return "success";
    }

}

3. 访问 localhost:8080/success

2019 - SpringBoot IDEA 配置 Freemarker 模板_第5张图片

你可能感兴趣的:(2019 - SpringBoot IDEA 配置 Freemarker 模板)