thymeleaf 是springboot默认的引擎模板
springboot 默认提供static 和 templates 两个 文件夹分别用来存放静态文件和动态文件
由于springboot默认采用thymeleaf 引擎模板,所以不需要配置一些页面映射和静态动态资源路径配置
springboot会默认去static和templates文件夹下面找
静态页面直接访问
http://localhost:8080/ index.html
动态页面访问
配置文件
可加可不加 # mvc: # view: # prefix: /templates/ # suffix: .html # static-path-pattern: /static/**
添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
index.html
<html lang="en">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>index</title>
</head>
<body>
我是首页
</body>
</html>
页面
bb.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
<title>submit 提交</title>
</head>
<body>
我是动态页面 <span th:text="${key}"> 2018 </span>
</body>
</html>
controller
@RequestMapping(value = "/tocc",method = RequestMethod.GET) public String savep(Model model) { model.addAttribute("key", 12345); return "bb"; }
页面