Search code examples
javathymeleaf

Display an image at the click of a button in thymeleaf java


I want to display an image in the browser from a click of a button.

In my view, I loop over a list that returns to me my controller. For each element of the list I would like to be able to display the image associated with the element. The images are in a folder placed at the root it is in the resources folder.

enter image description here

enter image description here


Solution

  • Use the <img> tag inside th:each.

    <img th:src="@{'/photos/' + ${vehicules.image}}"/>