简单使用:SpringBoot使用freemarker

柔情痞子 提交于 2019-12-03 15:03:41

使用步骤:

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

 

 

 

 

 

 

 

 

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!