SpringBoot2.x系列教程(二十八)freemarker基本语法使用

本篇文章带大家来了解一下freemarker的常见语法的基本使用。

ftl引入静态资源

style.css文件内容:

body{
    background-color: lightblue;
}

ftl文件中的引入:

<link href="/css/style.css" rel="stylesheet">

对于js或图片等效果使用方法相同。

简单类型

使用类似EL表达式。

${name}

包装类型

<td>${student.idNo}</td>
<td>${student.name}</td>

遍历集合/数组

<#list students as student>
    <tr>
        <td>${student.idNo}</td>
        <td>${student.name}</td>
    </tr>
</#list>

获取迭代索引

<#list students as student>
    ${student_index}
</#list>

判断条件

<#if grade == "A">
    ${student.name}
<#else>
    NoBody
</#if>

猜你喜欢

转载自blog.csdn.net/wo541075754/article/details/103945382