Tutorial 7
Tutorial 7
❖ Part 1:
▪ Create Java Spring Boot project in IntelliJ with autoconfiguration
▪ Create table with Hibernate
▪ Make CRUD feature with JPA
▪ Create view for web with Thymeleaf
❖ Introduction:
▪ Spring framework: a Java platform that provides comprehensive
infrastructure support for developing Java application
▪ Spring Boot: a tool that makes developing web application and microservices
with Spring framework faster and easier with autoconfiguration
▪ Hibernate: an object-relational mapping (ORM) tool for Java programming
language that simplifies the interaction with the database
▪ JPA (Java Persistence API): a collection of classes and methods to persistently
store that vast amounts of data into a database
▪ Thymeleaf: a modern server-side Java template engine for both web and
standalone environments
❖ Instructions:
1. Create new Java Spring Boot project in IntelliJ using Spring Initializr
➢ New Project
➢ Select Spring Initializr
➢ Input project parameters:
o Project name
o Project location
o Language: Java
o Type: Maven
o JDK: 19
o Java: 19
o Packaging: Jar Figure 1 - Create new Spring Boot project (1)
➢ Click Next
➢ Spring Boot version: 3.0.2
➢ Select dependencies:
o Spring Web
o Thymeleaf
o Spring Data JPA
o MySQL Driver
➢ Click Finish
Figure 5 - application.properties
3. Create Java class for model (entity) which acts as table in database (located at
sub-package model in src/main/java folder). Don’t forget to create get and set
function
Figure 6 - Employee.java
4. Create Java interface which extends JpaRepository for CRUD features (located
at sub-package repository in src/main/java folder)
Figure 7 - EmployeeRepository.java
5. Create Java class for controller which gets data from database and renders view
(located at sub-package controller in src/main/java folder)
Figure 8 - EmployeeController.java
Figure 10 - employeeDetail.html
7. Add sample data (records) to that table in database using MySQL Workbench
(refer to Tutorial 6) or integrated MySQL database in IntelliJ
Figure 11 – Setup connection to integrated MySQL database in IntelliJ (1)
❖ TASKS:
▪ Complete the remained operations for table CRUD including CREATE,
UPDATE and DELETE. You must add new methods in Controller then create
new corresponding HTML files (ex: employeeAdd.html)
• Compress the whole project and submit to FIT LMS with file name syntax:
FullName_StudentID_SE1_Tut7.zip
❖ Part 2:
▪ Practice use case diagram and use case template
❖ Exercise:
▪ A trader buys many stocks for different prices and in different quantities. The
Stock Trader program keeps track of a trader’s investments. This application
require user to login before using. A trader can use the program to buy stocks
or sell his stocks. The program is required to store information about all
stocks owned by a user, including the amount owned and other information
that the user may want to record, such as the date and price when
purchased. In addition, the program needs to be able to find out the current
price of any stock in the portfolio and to compute the current value of the
user’s investments.
❖ Task:
▪ Brainstorm about what features would a user need from the program and
how those features are provided to the user. Write the solution in a text
document. Also, draw a use case diagram to describe the features of the
program.
▪ Using use case template to discribe these features of the program.
▪ Submit a Word document then submit to FIT LMS with file name syntax:
FullName_StudentID_SE1_Tut7.docx