Exercises
Summary
Build a system based on previous work which uses an H2 in-memory database for storage following the
lecture notes.
Step 1
Follow through the lecture and build the demoed code. We will need this again, so be sure to do it!
Preferably, NOW, while you can get help!!!
Step 2
If you’re interested, create a data.sql file in the same place as your schema.sql file, and copy and paste the
following line into it:
INSERT INTO student(name) VALUES
('Sally'),
('Harminder'),
('Hao'),
('Jaspreet');
A data.sql is usually used to populate our database with any information we know we will require – at
startup! Just like a schema.sql, but for info rather than structure!
Explore the H2 console! If you type an SQL command to UPDATE or DELETE WHERE … something in a semi-
populated database here, then re-load http:
localhost:8080/ in a separate tab, does it reflect the
modification in real time?
Restart your Spring Boot app. Same thing?
Take a screenshot of your H2 console Student table with your name as the filename, be sure it shows a few
ows worth of student info inside, then submit your screenshot in SLATE for marks.
http:
localhost:8080
Exercises
Summary
Build a system based on previous work continuing to use our H2 in-memory database for storage following
the lecture notes. This time, use the MapSqlParameterSource to customize any and all data you insert, then
etrieve all Students you’ve inserted for display!
Step 1
Follow through the lecture and build the demoed code as ex52_jdbcTemplateContinued. We will need this
next class one more time, so be sure to do it! Preferably, NOW, while you can get help!!! Don’t drown here!
Our next exercise, building on this one, is one of the most important for the course!
Honestly, don’t you want to see it all working on your own machine anyway though?!
When you get it done, hand in a screenshot of your home page with your name already added to the
studentList at the top (also with your name as filename as always), and make sure you add a bunch of other
names added for good measure too! Style, style, style!!!
Assignment 1
This assignment is individual work. You are not allowed to work on this with anyone, nor
should you accept or offer help. Folks who offer help and hints generally produce very similar
code to the folks receiving help and hints! Offenders will be prosecuted!
Also note: these instructions are purposefully vague. There are an infinite number of ways to
solve this problem! Choose ways that work!
With that out of the way, put in the time, solve the problems, and get through it! It’s worth it,
and it’s fun!
The Ask…
Your boss misses going to the theatre during COVID! They ask you if you can develop an
application that allows your clients to review the few movies still playing in theatre, but
preferably any recent ones you can find that were released straight to Netflix or other
streaming services. You will hard-code static movie info that fits the criteria (in theatres now
or recently released straight to television), and then users can add reviews for any of the
movies as they see fit!
Requirements
Part 1
Begin with a POJO for each movie review and consider things you’d like to store. I might
suggest the movie name and an id number for it, the review itself as a String of course, and also
possibly the date and time the review was written, at bare minimum. Feel free to include
anything else you feel is relevant!
Set aside a memory hole for a POJOList (though please call it something more meaningful!), and
inject an implementation of said List as we have done in the exercises.
In a hard-coded constructor in your controller, hard-code at least three reviews for your
favourite movies and add them to your List. Be honest and choose carefully! Your boss (and I)
might decide to watch a few of them if you can sell us!
Friendly tip, a
ief hint about which streaming service each particular movie is playing on in
the review itself is also super helpful for me, though it’s a better idea to store the streaming
service info as an additional POJO property! Up to you! I mainly ask you keep the movie data
eal, and of course that you keep the reviews honest.
There is no need to link to any movie poster images for this assignment.
Part 2
Your Controller must dispatch to a form where the reviews are displayed.
You need a method which can handle HTTP GET request to “/”, as well as one for POST requests
with form data.
In your “/” mapped method, grab all movie reviews thus far from your list and add them to the
model. Additionally, add a blank Review to your Model for ModelAttribute binding in
Thymeleaf.
In your POST Mapped method, retrieve all form parameters as a @ModelAttribute annotation
and pre-populated POJO. Add the retrieved POJO info to your list. Then, retrieve all movie
eviews thus far from your list again and add them to the Model. Add a blank Review to your
Model for Form Binding back at Thymeleaf again.
Part 3
Create a Thymeleaf page or pages which display your dynamic review content! Display all
eview content for every review in a nicely formatted and styled fashion. Points for style here!
Additionally, add a form which is bound to your blank Review POJO from the Model to make it
easy to write, store, and retrieve the next review at our server side!
Style the page(s)! Again, points for style!
Things to consider
1. Think about the POJO properties you need in this application. Only one
POJO is required.
2. For the purposes of this application, no functionality for keeping
additional reviews in a more persistent state is wanted or required. They
should all disappear, not counting anything you’ve hard coded, with each
estart.
3. There can be any number of reviews for a particular movie stored in the database.
4. Ensure you pre-populate your list with a set of reviews for display so your
users aren’t lonely!
5. You must inject an implementation of your pojo list interface as we have done in
the exercises.
6. You must use Lombok.
7. Your view pages must use Thymeleaf, and they must look great! Most hackathons
are won by the best “looking” idea, rather than the actual best idea! Spend the
time!
Submission Details
Name your project A1
. Please use regular ZIP to combine and compress your
project’s directory from inside your workspace folder. Please DO NOT RAR or 7-Zip your project
for submission! RAR’s usually come with viruses. 7-Zip is very appropriate for email, but is
much harder to work with in Eclipse. Use a regular .zip and follow this naming convention –
you have officially been told! Failure to follow these two simple rules will result in massive
grade reductions.
Submit your assignment to the SLATE Assignments folder for our course. You should
attach/upload the zip of your Eclipse workspace project folder.
Remember what you have learned and put it into practice! Best of luck!
Grading
• Controller Layer – appropriate calls, use of injection, etc. 5
• Model Layer – POJO, appropriate repository methods, etc. 5
• View Layer – Thymeleaf, Form Binding, etc. 5
• All best practices and instructions followed, and style! 5
20
Assignment 1
This assignment is individual work. You are not allowed to work on this with anyone, nor
should you accept or offer help. Folks who offer help and hints generally produce very similar
code to the folks receiving help and hints! Offenders will be prosecuted!
Also note: these instructions are purposefully vague. There are an infinite number of ways to
solve this problem! Choose ways that work!
With that out of the way, put in the time, solve the problems, and get through it! It’s worth it,
and it’s fun!
The Ask…
Your boss misses going to the theatre during COVID! They ask you if you can develop an
application that allows your clients to review the few movies still playing in theatre, but
preferably any recent ones you can find that were released straight to Netflix or other
streaming services. You will hard-code static movie info that fits the criteria (in theatres now
or recently released straight to television), and then users can add reviews for any of the
movies as they see fit!
Requirements
Part 1
Begin with a POJO for each movie review and consider things you’d like to store. I might
suggest the movie name and an id number for it, the review itself as a String of course, and also
possibly the date and time the review was written, at bare minimum. Feel free to include
anything else you feel is relevant!
Set aside a memory hole for a POJOList (though please call it something more meaningful!), and
inject an implementation of said List as we have done in the exercises.
In a hard-coded constructor in your controller, hard-code at least three reviews for your
favourite movies and add them to your List. Be honest and choose carefully! Your boss (and I)
might decide to watch a few of them if you can sell us!
Friendly tip, a
ief hint about which streaming service each particular movie is playing on in
the review itself is also super helpful for me, though it’s a better idea to store the streaming
service info as an additional POJO property! Up to you! I mainly ask you keep the movie data
eal, and of course that you keep the reviews honest.