添加依赖
org.springframework.boot spring-boot-starter-thymeleaf
配置文件application.properties
#排除静态文件夹 spring.devtools.restart.exclude=static/**,public/** #关闭thymeleaf缓存开发过程中无需重启 spring.thymeleaf.cache=false #设置编码 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML spring.thymeleaf.prefix=classpath:/templates/
新建UserController类
@Controller
public class UserController {
@GetMapping("/addUser")
public String addUser(Model model){
model.addAttribute("title","i miss cc very much");
return "addUser";
}
}
新建addUser.html
Title
标题是:
hello
访问localhost:8080/addUser
thymeleaf基础语法
常用的 th 属性
| 属性 | 含义 |
| th:text | 文本的赋值及替换 |
| th:value | 属性赋值 |
| th:each | 遍历循环一个元素 |
| th:if | 判断条件,th:unless,th:switch,th:case |
| th:insert | 代码块的引入,th:replace,th:include用于公共代码块提取 |
| th:fragment | 定义代码块,方便被th:insert引用 |



