简单使用:SpringBoot使用freemarker

使用步骤:html

a : 添加依赖spring

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

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

 

在resources.templates下建立user.ftl文件,内容以下spa

<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";}
相关文章
相关标签/搜索