CSS和Java脚本无法呈现404错误spring-boot

时间:2017-01-06 12:46:44

标签: javascript css spring-boot

以下是我正在使用的路径片段:

<link rel="stylesheet" type="text/templates.css" href="../templates/css/superfish.css" th:href="@{../templates/css/superfish.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/style.css" th:href="@{../templates/css/style.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/nivo-slider.css" th:href="@{../templates/css/nivo-slider.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/jquery.qtip.min.css" th:href="@{../templates/css/jquery.qtip.min.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/jquery-ui.css" th:href="@{../templates/css/jquery-ui.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/jquery.fancybox.css" th:href="@{../templates/css/jquery.fancybox.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/jquery.fancybox-buttons.css" th:href="@{../templates/css/jquery.fancybox-buttons.css}"/>

enter image description here

控制器:

 @RequestMapping(value="/", method= RequestMethod.GET)
    public String contactForm(@Valid @ModelAttribute("contact") Contact contact, BindingResult bindingResult,
                              HttpServletRequest request, Model model, Device device) throws IOException {

        System.out.println("Inside controller-----------------");

主要方法:

@SpringBootApplication
@ComponentScan("com.stidham")
public class StidhamFinancialApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(StidhamFinancialApplication.class);
    }

    public static void main(String[] args) {

        SpringApplication.run(StidhamFinancialApplication.class, args

        );
    }
}

只有html呈现,没有js或css。我已经尝试了几种方法,我目前的路径看起来是正确的,甚至当我输入路径时我的IDE自动填充。

在战争档案中,他们也在正确的位置。

enter image description here

mvn clean install构建正确,他们没有依赖性问题。这似乎就像一个简单的路径问题,在部署时无效。

---------------更新1 ---------------

<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" type="text/css" href="/css/superfish.css" />
    <link rel="stylesheet" type="text/css" href="/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/css/nivo-slider.css" />
    <link rel="stylesheet" type="text/css" href="/css/jquery.qtip.min.css" />
    <link rel="stylesheet" type="text/css" href="/css/jquery-ui.css" />
    <link rel="stylesheet" type="text/css" href="/css/jquery.fancybox.css" />
    <link rel="stylesheet" type="text/css" href="/css/jquery.fancybox-buttons.css"/>

enter image description here 新路径

仍为js和css获得404:

enter image description here

1 个答案:

答案 0 :(得分:4)

文件夹&#34; templates&#34;只保留给thymeleaf来处理html。 JavaScript和CSS应该在文件夹&#34; static&#34;中。此文件夹直接映射到http。

的根URL

示例:文件位于... / resources / static /css/superfish.css

<link rel="stylesheet" href="/css/superfish.css" />