1,pom.xml,引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2,application.properties配置
#Thymeleaf配置
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=classpath:/templates
spring.thymeleaf.suffix=.html
2,文件目录

3,controller
package alu.controller; import javax.servlet.http.HttpServletRequest; import org.apache.ibatis.annotations.Delete; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.github.pagehelper.PageHelper; import alu.bean.User; import alu.service.TestService; import alu.util.JwtUtils; import io.jsonwebtoken.Claims; @Controller @RequestMapping("/user") public class TestController { @Autowired private TestService test; @RequestMapping(value = "/index") public String index(HttpServletRequest request){ PageHelper.startPage(0, 10); request.setAttribute("test", test.findAllVideo()); return "/user/index"; } @RequestMapping(value = "/indexT") public String isndex(HttpServletRequest request){ request.setAttribute("test", "asdasda"); return "/index"; } }
4,html存放位置

5,user里的index页面
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>index</title>
</head>
<body>
<div class="row">
<div class="col-md-5">
<table class="table table-hover" id="tab">
<thead>
<tr>
<th>id</th>
<th>title</th>
<th>summary</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr th:each="ItemList : ${test}">
<td th:text="${ItemList.id }"></td>
<td th:text="${ItemList.title }"></td>
<td th:text="${ItemList.summary }"></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
效果:

原文:https://www.cnblogs.com/mangoubiubiu/p/12905306.html