2015-12-02 76 views
0

我有我的index.html thymeleaf页面来了,但我在页面上引用的CSS没有被发现。引用一个.css文件与百里香在春天mvc使用th:href

<link href="../css/bootstrap.min.css" rel="stylesheet" th:href="@{/css/bootstrap.min.css}" type="text/css"/> 

这里是部署WAR的样子在Tomcat中: enter image description here

中的index.html是在模板文件夹。

但我收到以下错误在Chrome控制台:

GET http://localhost:8080/pocApp/css/bootstrap.min.css 404(未找到)

如果我能得到index.html页面精细为什么不能thymeleaf servlet找到那个文件?我试图将整个css目录粘贴到目录结构中的各个位置,例如在WEB-INF和WEB-INF/classes中,但没有运气。

回答

0

这个网站正在迅速成为我的橡皮鸭,因为这是我回答自己的第二个问题。

在我的春节,4 Java的配置我有这样的:

public class SpringWebConfig extends WebMvcConfigurerAdapter { 

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/resources/**") 
      .addResourceLocations("/resources/"); 
} 

所以我不得不调整自己的目录,并更改样式表的URL。

新的目录结构: enter image description here

从我的index.html

<link href="../resources/css/bootstrap.min.css" rel="stylesheet" th:href="@{/resources/css/bootstrap.min.css}" type="text/css"/> 
+0

欢迎来到我的世界,新的代码片段。我只是假设我知道比大多数,因为我不问很多问题,当我这样做时,我回答自己。 :( – Switch