Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.