SpringBoot FreeWorker模板技术解析

这篇文章主要介绍了SpringBoot FreeWorker模板技术解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

一、添加依赖

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

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

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中的遍历:

三、Controller中的测试代码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。