1.Freemarker相关maven依赖
<!-- 引入freemarker模板引擎的依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2.Freemarker基础配置(application.properties)
# 是否开启thymeleaf缓存,本地为false,生产建议为true
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
spring.freemarker.allow-request-override=false
spring.freemarker.check-template-location=true
#类型
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=true
spring.freemarker.expose-session-attributes=true
#文件后缀
spring.freemarker.suffix=.ftl
#路径
spring.freemarker.template-loader-path=classpath:/templates/
3.建立文件夹
1)src/main/resources/templates/freemarker/
2)建立一个testfreemarker.ftl
testfreemarker.ftl
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>freemarker test</title>
</head>
<body>
<h1>${serverdata.serverclasspath}</h1>
<h1>${serverdata.servername}</h1>
</body>
</html>
注:${serverdata.serverclasspath}、${serverdata.servername}获取后端controller返回数据
网友评论