【问题标题】:How can I add a proper thymeleaf source to my audio file?如何向我的音频文件添加适当的 thymeleaf 源?
【发布时间】:2021-01-14 11:37:20
【问题描述】:

我在将音频放入我的项目时遇到问题。
我认为thymeleaf src存在源码问题。
<audio id = "player" src = "../../sound/music1.mp3" th:src="@{/sound/music1.mp3}"></audio>
        <a onclick = "document.getElementById('player').play()">
            <img th:src="@{/img/ic_play_arrow.png}"></a>
        <a onclick = "document.getElementById('player').pause()">
            <img th:src="@{/img/ic_pause.png}"></a>
        <a onclick = "document.getElementById('player').volume += 0.1">
            <img th:src="@{/img/ic_volume_up.png}"></a>
        <a onclick = "document.getElementById('player').volume -= 0.1">
            <img th:src="@{/img/ic_volume_down.png}"></a>

以上代码属于基于片段的。
它被放在这样的视图中:

<div th:insert="fragments/nav :: header"></div>

我的文件结构如下所示:

图片效果很好。
在 Intellij 中通过浏览器打开文件时音频有效。

【问题讨论】:

  • Audio works when file opened by browser in Intellij. 这是什么意思?还向我们展示在&lt;audio .. 周围的浏览器上生成的 HTML
  • 欢迎来到 Stack Overflow!寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。见:How to create a Minimal, Complete, and Verifiable example
  • 看起来music1.mp3直接在static目录下,而不是static/sound

标签: java html spring intellij-idea thymeleaf


【解决方案1】:

问题解决了! 是 Spring 安全性阻止了 /sound 文件夹。
添加后:

                .antMatchers("/sound/**").permitAll()

音乐响起。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2016-11-30
    • 2020-09-24
    • 1970-01-01
    相关资源
    最近更新 更多