如何使用Thymeleaf在Micronaut中加载CSS文件?
这是我的index.html
内容:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Demo</title>
<link th:href="@{public/style.css}" type="text/css" rel="stylesheet" />
</head>
<body></body>
</html>
这是application.yml
:
router:
static:
resources:
default:
enabled: true
mapping: /**
paths: 'classpath:public'
图片说明:
您的配置中存在两个错误:
mapping: /**
会将公共文件夹绑定到您的应用程序的根路径,即文件将在<BASE_URL>/style.css
上提供,但您希望它在您的HTML文件中位于<BASE_URL>/public/style.css
。micronaut
而不是router
开始以下配置为您解决了以下问题:
micronaut:
router:
static-resources:
default:
enabled: true
mapping: "/public/**"
paths: "classpath:public"
映射mapping: /**
将它安装在根目录下。如果你想在public
下使用它,你可能想要在该映射中添加/public
前缀