Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring Basics Modeling, Storing, and Presenting Data Feeding Data to Our Thymeleaf Templates

Arnór Kristmundsson
Arnór Kristmundsson
2,013 Points

ModelMap doesn't work, Model does

Following Chris' steps, when I open http://localhost:8080/gif the alternate text appears. When I inspect the element I see that Thymeleaf generated

<img th:src="@{/gifs/gif.name.gif'" alt="gif" />

But it works if I replace the ModelMap parameter of the gifDetails function in the GifController class with a Model parameter, i.e.

@RequestMapping(value = "/gif")
public String gifDetails(Model model) {
    Gif gif = new Gif("compiler-bot", LocalDate.of(2015, 2, 13), "Chris Ramacciotti", true);
    model.addAttribute("gif",gif);
    return "gif-details";
}

I wonder why this is.

1 Answer

This is dated, but the "/gifs/gif.name.gif" does not look correct (obvious, right? ;)
I recommend checking your Thymeleaf quotations in the view.