springboot+mybatis+SQL Server整合可以看之前的文章
https://blog.csdn.net/Oceansssss/article/details/122668633
- templates文件下创建html文件
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>CRUD</title>
</head>
<body>
<table border="1" style="width: 350px;">
<tr>
<th>用户ID</th>
<th>用户姓名</th>
<th>用户性别</th>
</tr>
<tr th:each="MyUser_1:${userList}">
<td th:text="${MyUser_1.uid}"></td>
<td th:text="${MyUser_1.uname}"></td>
<td th:text="${MyUser_1.usex}"></td>
</tr>
</table>
- controller层添加以下代码
注意控制器类的注解是@Controller而不是@RestController
@RequestMapping("/hello")
public String helloHtml(Model model) {
model.addAttribute("userList",myUserService.findAll());
return "index";
}
- 运行结果
完整源代码https://download.csdn.net/download/Oceansssss/85237677