我正在用 spring MVC 和 Thymeleaf 做一个项目。我有一个问题,如果我有这个文件夹结构,我应该如何引用我的 CSS 文件:
src
main
webapp
resources
myCssFolder
myCssFile.css
web-inf
spring
views
myViewFolder
index.html
我的配置类是这样的:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**").addResourceLocations("/css/**");
registry.addResourceHandler("/img/**").addResourceLocations("/img/**");
registry.addResourceHandler("/js/**").addResourceLocations("/js/**");
registry.addResourceHandler("/sound/**").addResourceLocations("/sound/**");
registry.addResourceHandler("/fonts/**").addResourceLocations("/fonts/**");
}
我打电话href
在我的索引文件中,如下所示:
href="resources/css/bootstrap.min.css"
但我的页面中有些元素有点混乱,例如 CSS 不起作用。
您将需要使用th:href
用于引用 css 文件的属性。这是 thymeleaf 教程的示例。如果thymeleaf无法评价th:href
值,默认为href
value.
<head>
<title>Good Thymes Virtual Grocery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" media="all"
href="../../css/gtvg.css" th:href="@{/css/gtvg.css}" />
</head>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)