一、创建目录
二、设置 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";
}
}