之前的静态资源问题是由于拦截没有放行导致的,今天的这个问题主要是前端路径没有弄好
打开浏览器调试,发现静态资源请求路径前面多了个emp
正常的应该是:
,后来发现前端页面的静态资源地址是通过href指定的
<!-- Bootstrap core CSS -->
<link href="asserts/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="asserts/css/dashboard.css" rel="stylesheet">
因为之前是引入了webjar的方式,所以应该通过th:href来指定:
<!-- Bootstrap core CSS -->
<link href="asserts/css/bootstrap.min.css" th:href="@{/webjars/bootstrap/4.0.0/css/bootstrap.css}" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="asserts/css/dashboard.css" th:href="@{/asserts/css/dashboard.css}" rel="stylesheet">
href始终从端口开始作为根路径,如http://localhost:8080/channel/page/add
th:href会寻找项目路径作为根路径,如http://localhost:8080/dx/channel/page/add
补充:1.src 是指向物件的来源地址,是引入。在 img、script、iframe 等元素上使用。
2.href 是超文本引用,指向需要连结的地方,是与该页面有关联的,是引用。在 link和a 等元素上使用。
使用区别:
src通常用作“拿取”(引入),href 用作 “连结前往”(引用)。