#images in a folder -- Spring // Thymeleaf

4 messages · Page 1 of 1 (latest)

forest saddle
#

So I am new to spring and want to organize my pictures in a folder like so:
Resources:
Static:
Images:
image.png
CSS:
etc:

(with my images in their own folder in static )

currently I only know how to just put them right into static like this:

    @GetMapping("/imgTest")
    public String getImageTest(Model model, @RequestParam(
                                            name= "img",
                                            required = false,
                                            defaultValue = "default.png") String imageName){

        model.addAttribute("imgName", imageName);
        return "imageTest";
    }

then my template being:

<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Image test</title>
</head>
<body>
  <img th:src="/${imgName}" alt="AAA"/> <!-- for good luck -->

    <div>

    </div>
</body>
</html>
limber spadeBOT
#

This post has been reserved for your question.

Hey @forest saddle! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

spark mortar
#

update your template /image/${imgName}