springboot中样式表单 http://localhost:8080/login 未加载,因为它的 mime 类型
时间: 2024-01-01 10:06:10 浏览: 29
这个问题通常是由于静态资源的 MIME 类型配置不正确引起的。在 Spring Boot 中,可以通过在 `application.properties` 或 `application.yml` 中添加以下配置来解决这个问题:
```
spring.resources.static-locations=classpath:/static/
```
或
```
spring.resources.static-locations=classpath:/public/
```
这将告诉 Spring Boot 在类路径下寻找静态资源,并将其提供给客户端。如果你的静态资源不在 `classpath:static/` 或 `classpath:public/` 目录下,请相应地修改配置。
另外,如果你使用的是 Thymeleaf 模板引擎,还需要在模板文件中正确地引用静态资源,例如:
```html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Login</title>
<link th:href="@{/css/style.css}" rel="stylesheet"/>
</head>
<body>
<!-- 页面内容 -->
<script th:src="@{/js/main.js}"></script>
</body>
</html>
```
这里的 `@{/css/style.css}` 和 `@{/js/main.js}` 表示使用 Thymeleaf 提供的 URL 路径解析器来生成正确的 URL,以便浏览器可以正确加载静态资源。