使用thymeleaf模板
1.pom.xml文件中添加依赖
<!-- thymeleaf 模板 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.application.properties文件中配置缓存
spring.thymeleaf.cache=false
3.src/main/resources 文件夹下templates文件夹下添加模板文件index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1 th:text="${ax}">fail</h1>
</body>
</html>
4.新建HelloIndexController
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/hello")
public class HelloIndexController {
@RequestMapping()
public String index(ModelMap modelMap) {
modelMap.put("ax", "hello,world!");
return "index";
}
}