一、添加依赖

 <!--模板依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>

 

二、在resources/templates 目录下创建 后缀名为 .ftl 的文件

SpringBoot 模板技术 之 FreeWorker

 

 

ftl文件中的语法:基础模板和html一样

<html>
    <head>
        <title>car</title>
    </head>
    <body>
        <table align="center" border="1px" cellspacing="0px" cellpadding="10px">
            <thead>
                <tr>
                    <th>品牌</th>
                    <th>价格</th>
                </tr>
            </thead>
            <tbody>
                <#list carList as car>
                    <tr>
                        <td>${car.brand}</td>
                        <td>${car.price}</td>
                    </tr>
                </#list>
            </tbody>
        </table>
    </body>
</html>

 

ftl中的遍历:

SpringBoot 模板技术 之 FreeWorker

 

 三、Controller中的测试代码

SpringBoot 模板技术 之 FreeWorker

 

 

 

 

 

 

 

 

 

相关文章:

  • 2022-01-26
  • 2022-01-12
  • 2021-07-01
  • 2021-11-20
  • 2022-01-13
  • 2021-06-22
  • 2022-01-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2021-06-08
  • 2021-07-10
相关资源
相似解决方案