我有兩個端點,每個端點都回傳“index.html”視圖。
http://localhost:8080/ 這個 URL 顯示了索引檔案,CSS 也可以正常作業。圖片
http://localhost:8080/product/1 此 URL 僅顯示索引檔案,但未加載 CSS。圖片
主控制器.java
package com.example.temporary.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MainController {
@RequestMapping("/")
public String index() {
return "index";
}
@RequestMapping("/product/1")
public String process() {
return "index";
}
}
索引.html
<!DOCTYPE html>
<html lang="en">
<head xmlns:th="http://www.thymeleaf.org">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" th:href="@{css/index.css}">
<title>Document</title>
</head>
<body>
<h1>Index Page</h1>
<a th:href="@{/product/1}">Click Me!</a>
</body>
</html>
索引.css
* {
box-sizing: border-box;
}
body {
background-color: black;
color: white;
}
檔案結構 圖片
uj5u.com熱心網友回復:
嘗試在 html 中包含如下 css
<link rel="stylesheet" th:href="@{/css/index.css}">
而不是css/index.css它應該是/css/index.css
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/437440.html
