HTML in Spring Boot does not find files

Asked

Viewed 41 times

-1

I’m trying to load an audio file into an html, like this

inserir a descrição da imagem aqui

When I open html in the browser it loads normally

inserir a descrição da imagem aqui

However when I do the same I start the spring application, html does not load the file and it is the same file (wtf).

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

What I don’t understand is what the audio tag src has to do with spring boot.

NOTE: I am only using Thymeleaf and spring-web as dependencies in POM.

  • Hello Voce has to pass xmlns:th="http://www.thymeleaf.org"> in html file and download Thymeleaf dependency in pom.xml file

1 answer

0


Some steps should be followed to have Thymeleaf in a spring boot project.

Dependencies

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
 <groupId>nz.net.ultraq.thymeleaf</groupId>
 <artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>

Html header

If not using a reference layout, try using this html header

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

To understand how layouts work (when you create a foundation, you can use it on other pages): see here

Reference to resources

To refer to a static resource (images, css files, etc) always use the syntax of @{'/pasta_do_recurso/arquivo.extensao'}

Example: @{'/css/estilo.css'} for the case of a file located in src/main/resources/static/css/estilo.css

Most complete example below. Remember that always use the prefix before the default html tag... this prefix that was referenced at the beginning of html for Thymeleaf, in this case the th: <img th:src="@{/img/minha-logo.png}">

Do so by placing your mp3 file in a folder within a folder within Static, for example, and referencing it according to the name of that folder. It’s a common practice.

I believe the following would be next for a folder /static/audios containing the file mp3:

<audio th:src="@{/audios/musica.mp3}" controls></audio>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.