如何使用Thymeleaf在Micronaut中加载css文件?

问题描述 投票:0回答:2

如何使用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'

图片说明:

thymeleaf micronaut
2个回答
0
投票

您的配置中存在两个错误:

  1. 正如Graeme Rocher所提到的,mapping: /**会将公共文件夹绑定到您的应用程序的根路径,即文件将在<BASE_URL>/style.css上提供,但您希望它在您的HTML文件中位于<BASE_URL>/public/style.css
  2. 您的配置未正确定义。即它应该从micronaut而不是router开始

以下配置为您解决了以下问题:

micronaut:
  router:
    static-resources:
      default:
        enabled: true
        mapping: "/public/**"
        paths: "classpath:public"

3
投票

映射mapping: /**将它安装在根目录下。如果你想在public下使用它,你可能想要在该映射中添加/public前缀

© www.soinside.com 2019 - 2024. All rights reserved.