美文网首页
thymeleaf之导入js css

thymeleaf之导入js css

作者: 清水jx | 来源:发表于2019-05-31 10:53 被阅读0次

thymeleaf导入js css文件无效,一直报404

一 路径问题

引用静态资源如下,分为相对路径和绝对路径

1 相对路径

<link rel="stylesheet" type="text/css" th:href="@{/vanilla-cream-css/css/bootstrap.css}" />
<script type="text/javascript"   th:src="@{/js/jquery.min.js}"></script>

2 绝对路径

<link rel="stylesheet" type="text/css" th:href="@{~/vanilla-cream-css/css/bootstrap.css}" />

css 、 js 等文件放在 static文件夹下;html 文件放在templates文件夹下

二 编写MVC配置类问题

是否编写了mvc的配置类?如果是的话那就直接实现WebMvcConfigurer,不要继承WebMvcConfigurerationSupport,继承后者表明完全接管springMvc,会导致springBoot的默认设置都丢弃掉。

在SpringBoot2.0及Spring 5.0 WebMvcConfigurerAdapter已被废弃,目前有解决方案就有两种

1 直接实现WebMvcConfigurer (官方推荐)

@Configuration
public class WebMvcConfg implements WebMvcConfigurer {
    //todo
}

2 直接继承WebMvcConfigurationSupport

@Configuration
public class WebMvcConfg extends WebMvcConfigurationSupport {
        //todo
}

相关文章

网友评论

      本文标题:thymeleaf之导入js css

      本文链接:https://www.haomeiwen.com/subject/ewqwtctx.html