thymeleaf資源加載問題(從Controller跳轉)


 1 <!DOCTYPE html>
 2 <html xmlns:th="http://www.thymeleaf.org">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 5     <title>Login</title>
 6     <!-- 第一種方式:<base> 標簽為頁面上的所有鏈接規定默認地址或默認目標 -->
 7     <base th:href="@{/}">
 8     <!-- 上面定義了base路徑標簽,那么這里的css路徑就可以直接寫css路徑,Springboot中,static文件夾默認就是靜態資源文件夾,所以這里static/css/mycss.css可以不寫static/了 -->
 9     <link href="css/mycss.css" rel="stylesheet">
10  
11     <!-- 如果不使用base,那么這種方式也是可以的,@{/你的文件路徑},缺陷就是每次引用都必須帶上th:src="@{/}"這個才能正確引用,具體用什么方式,看你們自己 -->
12     <script th:src="@{/js/myjs.js}"></script>
13  
14 </head>
15 <body onload="f()">
16 <!--<div style="text-align: center;margin:0 auto;width: 1000px; ">-->
17 <div class="mydiv">
18     <h1>配置Thymeleaf模板</h1>
19     <table width="100%" border="1" cellspacing="1" cellpadding="0">
20         <tr>
21             <td>姓名</td>
22             <td>年齡</td>
23             <td>地址</td>
24         </tr>
25         <tr th:each="Admin:${list}" >
26             <td th:text="${Admin.id}"></td>
27             <td th:text="${Admin.a_id}"></td>
28             <td th:text="${Admin.a_pwd}"></td>
29         </tr>
30     </table>
31     <h2>ddd</h2>
32 </div>
33 </body>
34 </html>

個人比較傾向於在頭部添加<base th:href="@{/}">標簽,這樣就不用在每個需要引入的地方都使用Thymeleaf th:href="@{/路徑}"語法.

 

參考:https://blog.csdn.net/PLA12147111/article/details/85131786


免責聲明!

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



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