簡體   English   中英

無法在百里香中添加css文件

[英]Not able to add css file in thymeleaf

我是thymeleaf的新手,試圖在thymeleaf中添加.css文件,但無法加載css文件。 我的css文件在src / main / resources / templates / style.css中

 <!DOCTYPE html>
 <html xmlns:th="http://www.thymeleaf.org">

 <head>
 <title>State 1 for Document</title>
 </head>

 <div th:if="${InstaPanState==1 and InstaPanStateStatus==0}">
 <head lang="en">
    <title>Instaveritas PAN Verification</title>
    <link rel='stylesheet prefetch' 
   href='https://fonts.googleapis.com/css?family=Open+Sans:400,300' 
    th:href="@{https://fonts.googleapis.com/css?
    family=Open+Sans:400,300}"/>
    <link rel='stylesheet prefetch' 
     href='https://fonts.googleapis.com/css?family=Open+Sans:400,300' 
     th:href="@{https://fonts.googleapis.com/css?
     family=Open+Sans:400,300}" />
    <link type="text/css" rel="stylesheet" href="style.css"  
    th:href="@{/style.css}" media="all"/>
</head>

您需要添加資源映射,請參見http://www.baeldung.com/spring-mvc-static-resources

您可以在名為static的資源下創建一個文件夾,並在名為css的子文件夾下創建一個css文件,然后將其移動到此處,例如: resources/static/css/style.css

然后像這樣調用它:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM