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!

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

Henry Lin
Henry Lin
11,636 Points

It seems the key name of a modelMap is used to access the field of a gif object in HTML right?

In order to verify this, I did this:

    public String gifDetails(ModelMap modelMap) {
        Gif gif = new Gif("cowboy-coder", LocalDate.of(2018,10,26),"Henry Lin",true);
        return "gif-details";

And access it in html like this:

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

When I access the /gif page, it gave me:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Oct 26 15:57:22 EDT 2018
There was an unexpected error (type=Internal Server Error, status=500).
Exception evaluating SpringEL expression: "gif.name" (gif-details)

Does anyone know why? Please Help

3 Answers

I have the same problem, Can't not access keyName of ModelMap from html file

Martin Klestil
Martin Klestil
5,520 Points

I had a similar error, check out the error message from Intellj. It should show you what goes wrong with RequestMapping.

One way to see for sure what element Thymeleaf is generating, once you run the app and get the error, hit f12 and look at the error that should be highlighted somehow in that f12 display. In one case for me, I was creating a Gif object with an image name that included the file extension; so, Thymeleaf was generating image.gif.gif. If the app runs successfully, check again in the f12 area, in the 'elements' tab to see the correct path generated in <img> tag.