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