使用步骤:

a : 添加依赖

b: 创建模板文件 保存位置resources/templates 目录下 文件后缀名.ftl

c 编写controller 把结果传递给模板

 

在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";
}

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2019-11-05 20:36  MyBeans  阅读(1408)  评论(0编辑  收藏  举报