Springboot版本1.5.17
结合thymeleaf,在项目中引用CSS文件的问题

	    <parent>
	        <groupId>org.springframework.boot</groupId>
	        <artifactId>spring-boot-starter-parent</artifactId>
	        <version>1.5.17.RELEASE</version>
	        <relativePath/> <!-- lookup parent from repository -->
	    </parent>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
<!DOCTYPE html >
<html  lang="zh-CN" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8" />
    <title>0.0</title>
    <link  rel="stylesheet" type="text/css"  href="../static/css/index.css">
</head>

首先配置的CSS引用是这样,href后面跟上从static文件后的完整路径,打开静态网页就是有css效果了
Springboot开发中的一些小坑——CSS失效问题
没有加载成功是这样的
Springboot开发中的一些小坑——CSS失效问题
但是问题来了,还有种说法是这样加:

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

而在静态网页中,你看到的,始终是带上了CSS样式的结果,但Springboot项目运行起来后,你会发现CSS加载失效了,所以如果是Springboot项目,一定要加上后面的路径th:href=""。

相关文章:

  • 2021-08-01
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2021-10-27
猜你喜欢
  • 2021-10-30
  • 2021-12-29
  • 2021-10-19
  • 2021-12-28
  • 2021-12-19
  • 2021-06-24
  • 2022-02-14
相关资源
相似解决方案