Thymeleaf – `th:href`属性问题:`@{/css/style.css}`

huangapple 未分类评论43阅读模式
英文:

Thymeleaf - problem with th:href="@{/css/style.css}"

问题

我知道这是关于Thymeleaf和CSS的另一个问题,但是:

```html
<span>&#169; 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 &amp; 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&#39;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 (&#39;application/json&#39;) is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Why &#39;application/json&#39; ?

Interesting thing is at address: `http://localhost:8080/css/style.css` I can see my CSS code, but somehow Thymeleaf generate form above `&lt;link&gt;` tag wrong address: `http://localhost:8080/static/css/style.css`



</details>


huangapple
  • 本文由 发表于 2020年4月10日 14:00:48
  • 转载请务必保留本文链接:https://java.coder-hub.com/61134820-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定