英文:
Thymeleaf - problem with th:href="@{/css/style.css}"
问题
我知道这是关于Thymeleaf和CSS的另一个问题,但是:
```html
<span>© 2020-<script type="text/javascript" th:src="@{/js/year.js}"></script> created by:</span>
它能正常工作。
<link rel="stylesheet" th:href="@{/webjars/bulma/0.8.1/css/bulma.min.css}"/>
它能正常工作。
<link rel="stylesheet" type="text/css" th:href="@{/css/style.css}"/>
它无法正常工作。
为什么呢?
所有设置都已经准备就绪
(.antMatchers("/", "/css/**", "/js/**", "/img/**", "/webjars/**")
在Chrome中出现错误:
由于其MIME类型('application/json')不是受支持的样式表MIME类型,且启用了严格的MIME检查,因此拒绝应用来自http://localhost:8080/static/css/style.css
的样式。
为什么是'application/json'?
有趣的是,在地址:http://localhost:8080/css/style.css
,我可以看到我的CSS代码,但不知何故,Thymeleaf在上面的<link>
标签之前生成了错误的地址:http://localhost:8080/static/css/style.css
。
<details>
<summary>英文:</summary>
I know this is another question about Thymeleaf & CSS, but:
<span>© 2020-<script type="text/javascript" th:src="@{/js/year.js}"></script> created by:</span>
it works.
<link rel="stylesheet" th:href="@{/webjars/bulma/0.8.1/css/bulma.min.css}"/>
it works.
<link rel="stylesheet" type="text/css" th:href="@{/css/style.css}"/>
**it doesn't work.**
why?
Everything is set up well
(.antMatchers("/", "/css/", "/js/", "/img/", "/webjars/")
In Chrome there is error:
Refused to apply style from `http://localhost:8080/static/css/style.css` because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Why 'application/json' ?
Interesting thing is at address: `http://localhost:8080/css/style.css` I can see my CSS code, but somehow Thymeleaf generate form above `<link>` tag wrong address: `http://localhost:8080/static/css/style.css`
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论