Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Create a Category Model1:40 with Chris Ramacciotti
In this video, you are tasked with creating a model for a `Category` object.
Okay, we're ready to tackle the category functionality of the application. 0:00 What we'd like to do is add the ability to assign each GIF object to a category. 0:05 Then, we can create a list of these categories that will be displayed by 0:10 clicking on the categories link in the navigation menu. 0:14 Upon clicking on each category, 0:18 we'll see a page containing all the GIFs that are part of that category. 0:20 So, first things first. 0:24 We need a category model. 0:26 The category model will be a POJO that contains an integer ID field, 0:28 as well as a string name field. 0:32 We'll also need getters and setters for those, and a constructor too. 0:35 Go ahead, pause the video and give it a shot. 0:39 When you're ready to check your work against mine un-pause, and 0:42 I'll show you what I did. 0:45 All right, welcome back. 0:48 Let me show you how I coded the category model. 0:49 This model is a bit simpler than our GIF model since it contains only two fields. 0:52 First of all, I created a class named category and 0:56 put it in the model package to keep things nicely organized. 0:58 Then I added two fields, an int for the ID and a string for the name. 1:02 After that I had IntelliJ generate a constructor as well as getters and 1:07 setters for those two fields, and that's it. 1:11 Nothing too crazy happening here. 1:14 Now if your fields are named in a slightly different manner, don't worry. 1:16 Just take note of your differences and adjust your code accordingly. 1:19 In particular, differences in field names, more importantly your getters and 1:22 setters,will matter when you code the Thymeleaf templates. 1:26 In any case, make sure you're following the convention of starting your getter 1:29 names with get, or is for any boolean fields. 1:33 If you use IntelliJ to generate getters and setters, this will be done for you. 1:36
You need to sign up for Treehouse in order to download course files.Sign up