1.配置文件在application.yml:
server:
port: 8900
spring:
# THYMELEAF
thymeleaf:
#开启模板缓存(默认值:true)
cache: false
#Check that the template exists before rendering it.
check-template: true
#检查模板位置是否正确(默认值:true)
check-template-location: true
#开启MVC Thymeleaf视图解析(默认值:true)
enabled: true
#模板编码
encoding: UTF-8
#要运用于模板之上的模板模式。另见StandardTemplate-ModeHandlers(默认值:HTML5)
mode: LEGACYHTML5
#在构建URL时添加到视图名称前的前缀(默认值:classpath:/templates/)
prefix: classpath:/templates/
#在构建URL时添加到视图名称后的后缀(默认值:.html)
suffix: .html
#Thymeleaf模板解析器在解析器链中的顺序。默认情况下,它排第一位。顺序从1开始,
#只有在定义了额外的TemplateResolver Bean时才需要设置这个属性。
template-resolver-order: 1
2.新建html文件:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>welcome</title>
<meta http-equiv="Content-Type" content="text/html; ch arset=UTF-8"/>
<link rel="stylesheet" type="text/css" media="all" href="../../css/gtvg.css" th:href="@{/css/gtvg.c ss}"/>
</head>
<body>
<p th:text="'hello, ' + ${name} + '!'"/>
</body>
</html>
3.新建controller: