a : 添加依賴
b: 創建模板文件 保存位置resources/templates 目錄下 文件后綴名.ftl
在resources.templates下創建user.ftl文件,內容如下
<html> <head> <title>springboot</title> </head> <body> <table border="1px"> <thead> <tr> <th>id</th> <th>用戶名</th> <th>密碼</th> <th>姓名</th> </tr> </thead> <tbody> <#list users as user> <tr> <td>${user.id}</td> <td>${user.username}</td> <td>${user.password}</td> <td>${user.name}</td> </tr> </#list> </tbody> </table> </body> </html>
dao層:
List<User> getAllUser();
Controller層:
@RequestMapping("/list")
public String show(Model mode){
List<User> users = userDao.findAll();
mode.addAttribute("users",users);
return "user";
}