intellij-idea - 如何在 Thymeleaf 链接标签中转义“@”字符?
问题描述
这是我的链接:
<link th:href="@{/lib/@fortawesome/fontawesome-free/css/all.min.css}"
href="../../static/lib/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet">
该文件夹以“@”符号开头。(我的 IDE IntelliJ Idea 对此提出了错误。)
更新:
我也试过这个,但它似乎不起作用:
<link th:with="linkString = '/lib/@fortawesome/fontawesome-free/css/all.min.css'" th:href="@{linkString}"
href="../static/lib/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet">
在这种情况下,开发控制台显示:
index:1 Refused to apply style from 'http://localhost:8080/linkString' because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
如果我更改文件夹名称并删除“@”,问题就会消失并且 CSS 会出现在页面上。
解决方案
尝试将您的链接地址保存在string
变量中并将其传递到您的页面上。并在 html 中尝试如下所示。
<link th:href="@{'/' + ${page}}" rel="stylesheet">
希望这有效!
推荐阅读
- javascript - 在 react-native 升级后,finally 参数显示未定义
- angular - 指令中的 EventEmitter 不在 Parent 中处理
- python - 根据条件替换熊猫中的值
- c++ - 如何实现线程安全的日志记录?
- maven - 如何从非 build-gradle 文件访问 Kotlin DSL 扩展?
- python - 将当前行值与前一行值进行比较
- r - 将磁盘帧写入 CSV 的最佳方法是什么?
- python - Tensorflow 2:如何分析自定义层的速度
- sql - SQL 查询中 varchar(32) 的输出不正确
- python - 如何从多个网页中读取表格,并将它们与 pandas 结合起来?