Spring Boot Thymeleaf CRUD Database Real-Time Project - PART 1

๐Ÿ“˜ Premium Read: Access my best content on Medium member-only articles โ€” deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.

โœ… Some premium posts are free to read โ€” no account needed. Follow me on Medium to stay updated and support my writing.

๐ŸŽ“ Top 10 Courses (Huge Discount): Explore My Courses โ€” Learn through real-time, project-based development.

โ–ถ๏ธ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube


In this PART 1, we will complete:
  1. Creating and Setup Spring Boot Project in Eclipse STS
  2. Database Setup
  3. Create JPA Entity - Employee.java

Use the below links to navigate different parts of this tutorial:

1. Spring Boot Thymeleaf CRUD Database Real-Time Project - PART 1
  • Create and Setup Spring Boot Project in Eclipse STS
  • Database Setup
7. Spring Boot Thymeleaf CRUD Database Real-Time Project - PART 7
  • Implement Sorting Feature

1. Create and Setup Spring Boot Project in Eclipse STS

1. Create a Spring Boot Project

There are many ways to create a Spring Boot application. You can refer to the articles below to create a Spring Boot application.

2. Maven Dependencies

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

3. Project Structure

2. Database Setup

Create a database with the name "demo" in the MySQL database server.
Weโ€™ll need to configure the MySQL database URL, username, and password so that Spring can establish a connection with the database on startup. 
Open application.properties and add the following MySQL database configuration:
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url=jdbc:mysql://localhost:3306/demo?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
spring.datasource.username=root
spring.datasource.password=root

# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type=TRACE
Make sure that you change the spring.datasource.username and spring.datasource.password properties as per your MySQL installation.
The spring.jpa.hibernate.ddl-auto = update property makes sure that the database tables and the domain models in your application are in sync. Whenever you change the domain model, hibernate will automatically update the mapped table in the database when you restart the application.
I have also specified the log levels for Hibernate so that we can debug the SQL queries it executes.

3. Create JPA Entity - Employee.java

package net.javaguides.springboot.model;

import jakarta.persistence.*;

@Entity
@Table(name = "employees")
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "email")
    private String email;
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
}

Run Spring boot app and demo

This tutorial explained very well with demo in below video tutorial:

Use the below links to navigate different parts of this tutorial:

1. Spring Boot Thymeleaf CRUD Database Real-Time Project - PART 1
  • Create and Setup Spring Boot Project in Eclipse STS
  • Database Setup
7. Spring Boot Thymeleaf CRUD Database Real-Time Project - PART 7 // working on it
  • Implement Sorting Feature

Comments

Post a Comment

Leave Comment