简单使用:SpringBoot使用freemarker

使用步骤:

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

猜你喜欢

转载自www.cnblogs.com/crazy-lc/p/11801412.html