zoukankan      html  css  js  c++  java
  • SpringBoot使用freemarker模板

    导入依赖

     <!-- 添加freemarker模版的依赖 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-freemarker</artifactId>
            </dependency>

    application.properties文件中新增freemarker配置

    ## Freemarker 配置
    spring.freemarker.template-loader-path=classpath:/templates/
    spring.freemarker.cache=false
    spring.freemarker.charset=UTF-8
    spring.freemarker.check-template-location=true
    spring.freemarker.content-type=text/html
    spring.freemarker.expose-request-attributes=false
    spring.freemarker.expose-session-attributes=false
    spring.freemarker.request-context-attribute=request
    spring.freemarker.prefix=/
    spring.freemarker.suffix=.ftl

    在src/main/resource/templates文件夹中创建helloFtl.ftl文件

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>index01</title>
    </head>
    <body>
        欢迎:
        <#list listThree as three >
            ${three}
        </#list>
    </body>
    </html>

    创建controller层

    @Controller
    @RequestMapping("/free")
    public class FreeMarkerController {
    @RequestMapping("/getThree") public String getThree(ModelMap map){ List<String> list=new ArrayList<>(); list.add("aa"); list.add("bb"); map.put("listThree",list); return "index"; } }

    浏览器测试

        

  • 相关阅读:
    20145220&20145209&20145309信息安全系统设计基础实验报告
    20145209 《信息安全系统设计基础》第8周学习总结
    R574
    gym102219
    102222F
    luogu 1337
    luogu 2503 & bzoj 2428
    18 BJ J
    poj 1981
    101992 I
  • 原文地址:https://www.cnblogs.com/wnwn/p/12016116.html
Copyright © 2011-2022 走看看