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>
Hello Voce has to pass xmlns:th="http://www.thymeleaf.org"> in html file and download Thymeleaf dependency in pom.xml file
– Marcello Eduardo