Spring Boot 整合Freemarker

pom.xml中添加依赖:


            org.springframework.boot
            spring-boot-starter-freemarker

修改application.properties(改为:application.yml)

# 配置freemarker
spring:
  freemarker:
    # 设置模板后缀名
    suffix: .ftl
    # 设置文档类型
    content-type: text/html
    # 设置页面编码格式
    charset: UTF-8
    # 设置页面缓存
    cache: false
    # 设置ftl文件路径
    template-loader-path:
      - classpath:/templates
  # 设置静态文件路径,js,css等
  mvc:
    static-path-pattern: /static/**

使用实例:

    @RequestMapping(value = "/toTest")
    public ModelAndView test(Model model) {
        model.addAttribute("test1","test1111");
        model.addAttribute("test2","test2222");
        ModelAndView modelAndView = new ModelAndView("model");
        return modelAndView;
    }

该路径下新建文件:resources/templates/model.tfl




    freemark


Hello ${test1} from test 1 resource freemark!

Hello ${test2} from test 2 resource freemark!

 

你可能感兴趣的:(Spring,Boot)