一、创建目录

二、设置 ftl 文件模板

<#--
Created by IntelliJ IDEA.
User: ${USER}
Date: ${DATE}
Time: ${TIME}
To change this template use File | Settings | File Templates.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>#[[$Title$]]#</title>
</head>
<body>
#[[$END$]]#
</body>
</html>
三、创建 ftl 文件

输入文件名即可。
四、配置 application.yml
# Spring的配置
spring:
# 模板配置
profiles: default
freemarker:
template-loader-path: classpath:/templates/views/ftl/
cache: true
check-template-location: true
content-type: text/html; charset=UTF-8
expose-request-attributes: true
expose-session-attributes: true
request-context-attribute: request
suffix: .ftl
五、访问及跳转
默认访问的是 index.ftl
1. 创建 success.ftl

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>欢迎</title>
</head>
<body>
<h1>哈哈success</h1>
</body>
</html>
2. 创建一个 Controller 控制器
public class Index {
@RequestMapping("success")
public String Index() {
return "success";
}
}
3. 访问 localhost:8080/success

该博客主要介绍了FTL文件相关操作。包括创建目录、设置ftl文件模板、创建ftl文件,还需配置application.yml。在访问及跳转方面,要创建success.ftl和Controller控制器,最后可通过访问localhost:8080/success进行测试,默认访问index.ftl。
753





