簡單使用: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";
}

 

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM