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

Is there any specific reason why the @RequestMapping for the gifDetails method is called "gif"? @RequestMapping("/gif")

I see that the name of the Gif object is called "gif" and also the first value of the modelMap.put method is also "gif" , does the name of the value in @RequestMapping HAVE to match anything else in the gifDetails method?

1 Answer

The first value in the modelMap.put method does not have to be gif. The value will determine how you access the properties of the gif object in the html code. Here are some scenarios.

// you place the gif object you created into the model

modelMap.put("gif", gif);

// To access properties of gif object in html file you use gif

<h4 th:text="${gif.username}"></h4>

If you want to change the "gif" in the modelMap.put to something else, like "changeFromGif" you have to change the access in the html file.

// Placing gif object into model

modelMap.put( "changeFromGif", gif);

// Accessing properties of gif object

<h4 th:text="${changeFromGif.username}"></h4>

The value in @RequestMapping(value="/gif") just means when a user goes to the /gif url, it will call the method below the request mapping annotation.

Hope this helps.