虽然我更倾向于说这是不可能的,但我似乎没有找到任何具体的答案。
但是,是否可以在外部 CSS 文件中使用 Thmymeleaf 表达式?例如,如果我有 main.css 并且它包含:
body {
font-size: [[${fooBean.isLarge ? '22px;' : '16px;' }]];
}
.header {
margin-top:
background: url{[[${fooBean.isMain ? '/img/blue.jpg' : '/img/red.jpg' }]]}
no-repeat center center fixed;
}
这完全有可能使用 Thymeleaf 吗?
最佳答案
Thymeleaf 3 introduced new template modes .其中之一是 CSS,you can see an example of one here .您必须设置所有 spring 的东西/ Controller ,但您应该能够像平常一样使用它们(将您的 fooBean 添加到模型中)。
关于css - Thymeleaf - 解析外部 CSS 文件?表达式、变量等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43082116/