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

标签 thymeleaf micronaut

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

图片注释:

resource directory structure

最佳答案

你的配置有两个错误:

  • 正如 Graeme Rocher 所说,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/

    相关文章:

    hibernate - 永远不会调用 Kotlin、Micronaut 和 Hibernate 自定义 bean validator

    java - Micronaut 是否需要异步编程?

    spring - Thymeleaf 文档中所需的字体未显示

    spring - hibernate 时存储的 LocalDate 错误

    javascript - 如何对动态生成的表行设置限制?

    performance - Grails 3 vs 4 性能、启动时间和内存

    amazon-web-services - 从 Cognito 身份池 identityId 获取 Cognito 用户池用户名

    java - 表单提交发送不需要的 GET 请求

    java - 使用 Thymeleaf onclick 调用服务方法

    Micronaut Controller 错误页面未找到