<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 一、Thymeleaf簡介 Thymeleaf 是一個服務器端 Java 模板引擎,能夠處理 HTML、XML、CSS、JAVASCRIPT 等模板文件。Thymeleaf 模板可以直接當作靜態原型來使用,它主要目標是為開發者的開發工作流程帶來優雅的自然模板,也是 Java 服務器端 HTML5 開發的理想選擇。 ## 二、集成 使用Maven坐標將thymeleaf引入到項目中 ~~~ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> ~~~ 對thymeleaf模板進行配置 ~~~ spring: thymeleaf: cache: false # 啟用緩存:建議生產開啟 check-template-location: true # 檢查模版是否存在 enabled: true # 是否啟用 encoding: UTF-8 # 模版編碼 excluded-view-names: # 應該從解析中排除的視圖名稱列表(用逗號分隔) mode: HTML5 # 模版模式 prefix: classpath:/templates/ # 模版存放路徑 suffix: .html # 模版后綴 ~~~ ## 三、Hello ThymeLeaf 例子完成之后,項目代碼結構如下: ![](https://box.kancloud.cn/f77873ca7ea16dc9523728386b9aeb0c_441x684.png) 查詢一個articles文章列表,并返回模板名稱,由Spring根據名稱找到模板進行頁面渲染 ~~~ @Controller @RequestMapping("/template") public class TemplateController { @Resource(name="articleMybatisRestServiceImpl") ArticleRestService articleRestService; @GetMapping("/thymeleaf") public String index(Model model) { List<ArticleVO> articles = articleRestService.getAll(); model.addAttribute("articles", articles); //模版名稱,實際的目錄為:resources/templates/thymeleaftemp.html return "thymeleaftemp"; } } ~~~ thymeleaf模板頁面 ~~~ <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head lang="en"> <meta charset="UTF-8" /> <title>thymeleaf簡單示例</title> </head> <body> <h1>Hello Thymeleaf</h1> <table class=""> <tr> <td>作者</td> <td>教程名稱</td> <td>內容</td> </tr> <!-- 用thymeleaf語法遍歷articles列表--> <tr th:each="item : ${articles}"> <td th:text="${item.author}"></td> <td th:text="${item.title}"></td> <td th:text="${item.content}"></td> </tr> </table> <img src="/image/template.png"> </body> </html> ~~~ ## 四、訪問測試 訪問測試地址:[http://localhost:8888/template/freemarker](http://localhost:8888/template/freemarker) ![](https://box.kancloud.cn/5eb0da512cb55d541f99dda5d2df87e1_760x825.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看