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 we boot our application to see our category service and DAO in action.
Git Command to Sync Your Code to the Start of this Video
git checkout -f s2v6
Using Github With This Course
You can complete this course entirely using code created by you on your local machine. However, if you choose to use the code I've made available to you, you have two options:
- Use the project files linked at the bottom of this page, or
- Use the Github repository I've made available (recommended)
If you choose the recommended option of using the Github repository, it can be found at
https://github.com/treehouse/giflib-hibernate
To utilize Github with this course, you can download the Github desktop client for your system or use the command line interface provided with Git.
Clone this repository to your machine using the Github desktop client, or using the following command:
git clone git@github.com:treehouse/giflib-hibernate.git
To update your local repository to match a video's starting point, you can use the git checkout
command in combination with the stage and video number. For example, to update your local repository to match the starting point of Stage 5, Video 4, you'd use the following:
git checkout -f s5v4
Notice the use of the -f option. This forces Git to override all local changes, so be aware: this will cause any changes you made to be lost.
-
0:00
Hey, great work over those last few videos.
-
0:03
You now have three application layers,
-
0:05
and hopefully a working implementation of those layers for category.
-
0:09
We have plenty of work left to do in giflib, but
-
0:11
we should fire it up now to make sure we're on the right path.
-
0:16
With our interfaces and implementations for category DAO and
-
0:19
service in place, and with our auto wired service in the category controller,
-
0:23
let's fire up our application.
-
0:25
Now, I'm assuming that your database server is still running, and
-
0:29
you've already inserted a row into the category table.
-
0:32
If not, we'll insert a second row in just a moment.
-
0:34
With that said, I'm gonna go ahead and run my boot run task.
-
0:38
If your server is still running, go ahead and hit the Stop button and
-
0:42
then you can rerun the task and let's see what happens here.
-
0:47
To make sure that everything compiles successfully and
-
0:50
that the spring application boots successfully without exceptions.
-
0:55
Looks like my application did indeed start successfully.
-
1:00
So let's switch to the browser.
-
1:04
Let me refresh this categories view to see if I still get my one category to display.
-
1:09
When I refresh and looks like I still successfully
-
1:14
grab that category using my new service DAO pattern.
-
1:18
Now, how about we switch to that H2 web console and
-
1:21
see what happens if we insert another row into the category table.
-
1:25
So I will go back here.
-
1:26
And let's do insert into category (name,
-
1:31
colorcode), we'll insert the values.
-
1:36
I'll put Java, remember that's a string.
-
1:38
Don't forget the single quotes as well as the hexadecimal code for
-
1:44
this color or whatever color you like, 35986.
-
1:49
Let's insert that, we'll run that.
-
1:53
If you get this message that simply means that your session has expired and
-
1:57
all you have to do is log in again.
-
1:59
Of course, you're gonna have to run that query again.
-
2:02
insert into category (name,
-
2:07
colorcode) values).
-
2:11
Get my codes in their first ('Java'
-
2:15
#b35986, let's try that one more time.
-
2:21
Cool.
-
2:22
Update count is one which means my row was inserted.
-
2:26
Now, what should happen is that when I flip back here and refresh my page,
-
2:30
I should see both of those categories technology and Java.
-
2:34
There it is.
-
2:36
Now, you might be wondering why the colors are the same since we
-
2:39
definitely chose different color codes for these categories.
-
2:43
Well, it's all about how the HTML and CSS is coded in this case.
-
2:48
And for this particular piece, the color is specified in the time leaf template.
-
2:52
And just so that we don't go too far in this course before interacting with our
-
2:56
timely views, let's open that now to prove that we can make noticeable changes.
-
3:02
So I'll switch back to IntelliJ, and I'm going to open the category Index Template.
-
3:09
So under templates, and category, let's open that index template.
-
3:14
Now, if we scroll down here, you'll eventually see a div
-
3:19
with a static background color set in its style attribute.
-
3:25
Now, you may have learned the rule of keeping your styling in your CSS files and
-
3:29
out of your HTML if you've done any front-end work.
-
3:32
But as with any rule, there are certainly exceptions.
-
3:35
If there is user data that's used to add custom styling to a page,
-
3:39
such as is the case here with a user specified color, this may be one of
-
3:44
those few scenarios where it's common practice to place that within the HTML.
-
3:49
In this case, we can prefix the style attribute with th or like this.
-
3:54
So that timely for process this attribute.
-
3:56
And you sometime leave concatenation to combine the background color with this
-
4:01
category objects color code field value.
-
4:06
So to trigger concatenation, we can use the vertical bars or the pipe symbol.
-
4:13
And instead of this statically set code we can place this expression,
-
4:18
cat.colorcode.
-
4:22
Now, let's save this template and reboot our application.
-
4:26
So I'll stop this spring app.
-
4:29
Let me trash that output there.
-
4:32
And I will rerun the boot run task.
-
4:36
And give it a moment to compile and to boot.
-
4:42
And let's switch back to the browser and refresh so I'm back here and
-
4:46
I'm going to refresh.
-
4:49
All right.
-
4:50
Look at those colors, pretty cool.
-
4:52
We've now touched all the layers of the apple both in the MVC architecture
-
4:56
as well as within the service DAO pattern.
-
4:59
In the next stage, we'll add a whole bunch of features to our app, allowing our
-
5:03
users to interact with the underlying data via our nicely designed user interface.
You need to sign up for Treehouse in order to download course files.
Sign up