pom 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
propreties配置文件
//设置编码
spring.freemarker.charset=utf-8
//设置前缀 文件夹
spring.freemarker.prefix=/ftl/
//设置后缀文件名
spring.freemarker.suffix=.ftl
//设置数字编码格式(默认超出999 会添加逗号 example: 1,000)
spring.freemarker.settings.number_format=0.##
ftl 模板
#例1
<#if msg==0>
<h1>失败</h1>
<#else>
<h1>成功</h1>
</#if>
#例2
<h1>
<table>
<th>Id</th><th>name</th><th>pid</th>
<#list pages.bookList as bookMsg>
<tr><td>${bookMsg.id}</td><td>${bookMsg.name}</td><td>${bookMsg.pid}</td></tr>
</#list>
</table>
<#list 1.. pages.pageInfo.pages as index>
<a href="itemsPage?currentPage=${index}&pageSize=${pages.pageInfo.pageSize}">第${index}页</a>
</#list>
</h1>
#例3
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<table>
<#list books as book>
<tr>
<td>${book.name}</td>
<td>${book.pid}</td>
</tr>
</#list>
</table>
<#include "ap.ftl">
</body>
</html>
网友评论