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