SpringBoot中html引用JS/CSS文件路徑問題


  • html 文件放在resources/templates下,在Controller請求處理方法返回時會自動到這個目錄下查找:

  • js/css 等靜態資源放在resources/static下,在html中引入時,會自動到這個目錄下查找:

 @RequestMapping("/index")
 public String index(){
     //返回一個指定頁面 index.html       
     return "index";
 }
  • 文件路徑

在index.html中引入JS文件時,寫法:

<script src="./js/sockjs.min.js"></script>
<script src="./js/stomp.min.js"></script>

如果Controller類名上有RequestMapping("/page"),src中要寫兩個".."

<script src="../js/sockjs.min.js"></script>
<script src="../js/stomp.min.js"></script>

原文章地址:https://blog.csdn.net/xiaobanv1/article/details/85116031


免責聲明!

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



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