zoukankan      html  css  js  c++  java
  • 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; 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

  • 相关阅读:
    matplotlib实战
    matplotlib常用操作2
    matplotlib 常用操作
    pandas总结
    朴素贝叶斯算法python实现
    什么叫“回归”——“回归”名词的由来&&回归与拟合、分类的区别 && 回归分析
    Latex常用整理
    准备尝试openFrameworks
    常用工具库总结
    K-Means和K Nearest Neighbor
  • 原文地址:https://www.cnblogs.com/116970u/p/10670899.html
Copyright © 2011-2022 走看看