问题页面
解决办法
在application.yml中加上freemarker解析器:
spring:
freemarker:
request-context-attribute: req #req访问request
suffix: .ftl #后缀名
content-type: text/html
enabled: true
cache: false #缓存配置
template-loader-path: classpath:/templates/ #模板加载路径 按需配置
charset: UTF-8 #编码格式
settings:
number_format: '0.##'
原程序:
controller:
@Controller
public class FreemarkerIndexController {
@RequestMapping("/freemarkerIndex")
public String freemarkerIndex(Map<String, String> result, HttpServletRequest req) {
result.put("name", "jsoncc");
return "freemarkerIndex";
}
}
模板中的 .ftl 文件调用name
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>title</title>
</head>
<body>
${name}
</body>
</html>
输出结果
thymeleaf
thymeleaf中在.html页面加上
<html lang="en" xmlns:th="http://www.thymeleaf.org">