一、pom.xml

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-freemarker -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
            <version>2.3.5.RELEASE</version>
        </dependency>

二、springboot配置文件

1.application.yml

#spring
spring:
  #Freemarker配置
  freemarker:
    allow-request-override: false
    cache: false
    check-template-location: true
    charset: UTF-8
    content-type: text/html; charset=utf-8
    expose-request-attributes: false
    expose-session-attributes: false
    expose-spring-macro-helpers: false
    ## 模版文件结尾.ftl
    suffix: .ftl
    ## 模版文件目录
    template-loader-path: classpath:/templates
  #设置不同环境配置文件读取
  profiles:
    active: dev

2.application-dev.yml

#开发环境
spring:
  #mysql
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/miaosha
    name: miaosha
    username: root
    password: 678678
    #druid
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
  #redis
  redis:
    host: 127.0.0.1
    port: 6379

3.application-prd.yml

#生产环境
spring:
  #mysql
  datasource:
    url: jdbc:mysql://IP地址:端口号/miaosha
    name: miaosha
    username: username
    password: password
    #druid
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
  #redis
  redis:
    host: IP地址
    port: 6379

三、Controller

1 @RequestMapping(value = "/toftl", method = {RequestMethod.GET})
2     public String toFreemarker1(Map<String,Object> map) {
3 
4         map.put("name", "测试freemarker和controller返回");
5         return "test_freemarker_1";
6     }

四、前端

1.resources层级

 

 2.test_freemarker_1.ftl

<!DOCTYPE html>
<html>
<head>
    <title>title</title>
    <meta charset="UTF-8">
</head>
<body>
${name}
</body>
</html>