1、前端
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<body>
<div th:text="${msg}">xxx</div>
</body>
</html>
2、后台
package com.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author dc
* @date 2020/5/20 - 15:08
*/
@Controller
public class MyController {
@RequestMapping("/index")
public String doFirst(Model model) {
model.addAttribute("msg", "springboot--thymekeaf");
return "/index";
}
}
3、主配置文件
#设置thymeleaf模板引擎的缓存,设置false为关闭,默认为true
#还得设置Edit Configurations 为update resources
spring.thymeleaf.cache=false
#设置thymeleaf模板引擎的前后缀(可选项),相当与springmvc中的内部资源解析器
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html