如何使用 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: /**
将公用文件夹绑定(bind)到应用程序的根路径,即文件将在 <BASE_URL>/style.css
可用但您希望它位于 <BASE_URL>/public/style.css
在您的 HTML 文件中。 micronaut
开头而不是 router
以下配置为您解决了这个问题:
micronaut:
router:
static-resources:
default:
enabled: true
mapping: "/public/**"
paths: "classpath:public"
关于thymeleaf - 如何使用 Thymeleaf 在 Micronaut 中加载 css 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54169477/