加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 在spring mvc中用thymeleaf引用一个.css文件

发布时间:2020-12-14 19:42:47 所属栏目:资源 来源:网络整理
导读:我正在做一个春季MVC和Thymeleaf的项目.如果我有这个文件夹结构,我有一个关于如何引用我的CSS文件的问题: src main webapp resources myCssFolder myCssFile.css web-inf spring views myViewFolder index.html 我的配置类是这样的: @Overridepublic void
我正在做一个春季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文件.以下是百里叶教程的示例.如果百里香叶无法评估th:href值,则默认为href值.
<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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读