【发布时间】:2020-01-20 13:17:51
【问题描述】:
我的应用程序无法找到我的静态文件时遇到问题。然而,这仅在一定程度上发生。从下面的代码片段中可以看出,css、图像、js 等适用于某些文件,而不适用于其他文件。不确定我在这里缺少什么。
我的堆栈:Spring Boot,Thymeleaf
我的 application.yml 文件的一部分:
server:
port: 8090
servlet:
context-path: /myapp
我的应用公共资源目录结构:
/resources
/public
/css
/images
/js
我的应用程序模板结构以及样式和图像的作用:
/resources
/templates/index.html (works)
/templates/admin/index.html (works)
/templates/admin/user/admin/showuser.html (does not work)
来自 /resources/admin/fragments/header.html 的代码(用作其他文件的头文件)
<!DOCTYPE html>
<html>
<head>
<link href="css/mycss.css" rel="stylesheet">
来自 /resources/templates/index.html 的代码(有效)(不包括 header.html 片段)
<link href="css/mycss.css" rel="stylesheet">
来自 /resources/templates/admin/index.html 的代码(有效)(包括 header.html 作为使用 Thymeleaf 的片段)
<!--/*/ <th:block th:include="/admin/fragments/header"></th:block> /*/-->
来自 /resources/templates/admin/user/admin/showuser.html 的代码(不起作用)(包括 header.html 作为使用 Thymeleaf 的片段)
<!--/*/ <th:block th:include="/admin/fragments/header"></th:block> /*/-->
不知道如何解决这个问题。 谢谢!
【问题讨论】:
标签: spring-boot thymeleaf static-content contextpath