Web development Using Java

Rashmi Mishra
0

 

🔷 Step-by-Step Guide: Employee Management System Using Java (Spring Boot & MySQL)

1️ Project Setup

Install Required Tools

  • JDK 17 or later – Java Development Kit
  • Spring Boot – Backend framework
  • MySQL – Database
  • Maven – Dependency management
  • Postman – API testing tool (Optional)
  • IDE (IntelliJ IDEA, VS Code, Eclipse, or STS)

Create a New Spring Boot Project

Use Spring Initializr (https://start.spring.io/) and select:

  • Spring Boot Version: Latest stable release
  • Dependencies:
    • Spring Web (for REST API)
    • Spring Data JPA (for database interactions)
    • MySQL Driver (for MySQL connectivity)
    • Lombok (to reduce boilerplate code)
    • Thymeleaf (if using JSP/HTML frontend)

Download the project and import it into your IDE.

 

 

🔹 What is JDK 17 or Later?

JDK (Java Development Kit) is a software development kit required to write, compile, and run Java applications. JDK 17 is a Long-Term Support (LTS) version of Java, meaning it will receive updates and support for an extended period.

🔹 Why Use JDK 17?

  • Performance Improvements: Faster startup and execution.
  • Security Updates: More secure than older versions.
  • Modern Features: Includes new Java features like records, pattern matching, and sealed classes.
  • LTS Support: JDK 17 is a Long-Term Support (LTS) version, meaning it's stable and recommended for enterprise applications.

🔹 How to Install JDK 17

1️ Download & Install JDK 17

  • Go to the Oracle JDK Download Page.
  • Download the JDK 17 version for your operating system (Windows, macOS, or Linux).
  • Install it by following the instructions.

Alternatively, you can install OpenJDK 17, which is a free, open-source version:

  • On Windows (using Chocolatey):

choco install openjdk17

  • On Ubuntu (using APT):

sudo apt update

sudo apt install openjdk-17-jdk

  • On macOS (using Homebrew):

brew install openjdk@17


2️ Verify Installation

After installation, check if JDK 17 is installed correctly by running:

java -version

Expected output:

java version "17.0.1" 2021-09-14 LTS

Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)

Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode)


3️ Set Up JAVA_HOME (Environment Variable)

Some tools (like Maven and Spring Boot) need JAVA_HOME to be set.

Windows

  • Open Command Prompt and run:

echo %JAVA_HOME%

  • If it's empty, set it manually:
    • Go to System Properties → Advanced → Environment Variables.
    • Click New under System Variables and add:

Variable Name: JAVA_HOME

Variable Value: C:\Program Files\Java\jdk-17

    • Restart the terminal and run:

echo %JAVA_HOME%

Expected output: C:\Program Files\Java\jdk-17

Linux / macOS

  • Open the terminal and add this to ~/.bashrc or ~/.zshrc:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk

export PATH=$JAVA_HOME/bin:$PATH

  • Apply changes:

source ~/.bashrc

  • Verify:

echo $JAVA_HOME


🔹 How JDK 17 is Used in Our Project

1.   Compile & Run Java Code

o    JDK 17 is required to compile our Employee Management System.

o    When you run mvn spring-boot:run, it uses JDK 17.

2.   Spring Boot Compatibility

o    Spring Boot 3 requires Java 17 or later.

o    Using Java 8 or 11 will not work for the latest Spring Boot versions.

3.   Building JAR Files

o    When you run mvn package, JDK 17 compiles the project and generates an executable JAR file.


🎯 Conclusion

  • JDK 17 is mandatory for running modern Spring Boot applications.
  • It provides better performance, security, and long-term support.
  • You must install JDK 17 and set up JAVA_HOME for Maven and Spring Boot to work properly.

🔹 What is Spring Boot?

Spring Boot is a powerful backend framework for building Java-based web applications and RESTful APIs. It is an extension of the Spring Framework that simplifies the development process by reducing boilerplate code and configuration effort.

Key Features of Spring Boot:

  • Auto Configuration – Automatically configures necessary components.
  • Embedded Servers – Comes with Tomcat, Jetty, and Undertow, so no external deployment is needed.
  • Spring Boot Starter Packs – Pre-configured dependencies to speed up development.
  • Production-Ready – Built-in monitoring, logging, and security features.
  • Microservices Ready – Perfect for developing scalable enterprise applications.

🔹 Why Use Spring Boot for Web Development?

1.   Rapid Development – No need for complex XML configurations.

2.   Enterprise-Grade – Used in large-scale, high-performance applications.

3.   REST API Support – Easily create APIs for web and mobile apps.

4.   Integration with Databases – Supports MySQL, PostgreSQL, MongoDB, and more.

5.   Secure – Built-in support for authentication and authorization (Spring Security).


🔹 How Spring Boot is Used in Our Employee Management System

In the Employee Management System, Spring Boot will handle the backend logic:

  • Expose REST APIs to perform CRUD operations (Create, Read, Update, Delete).
  • Connect to a MySQL database to store employee data.
  • Use Spring MVC for handling web requests.
  • Use JPA (Java Persistence API) for database operations.

Technologies Used

Technology

Purpose

Spring Boot

Backend framework

Spring MVC

Handles HTTP requests

Spring Data JPA

Database interaction

Hibernate

ORM (Object Relational Mapping)

MySQL

Database storage

Spring Security

Authentication & Authorization


🔹 How to Set Up a Spring Boot Project (Step by Step)

1️ Create a Spring Boot Project using Spring Initializr

  • Go to Spring Initializr
  • Select:
    • Project: Maven
    • Language: Java
    • Spring Boot Version: 3.1+ (Requires JDK 17+)
    • Dependencies:
      • Spring Web – To create REST APIs
      • Spring Data JPA – To interact with MySQL
      • MySQL Driver – To connect to MySQL database
      • Spring Boot DevTools – For auto-reloading during development
  • Click Generate and download the project.

2️ Open the Project in an IDE

  • Extract the downloaded ZIP file.
  • Open it in IntelliJ IDEA, Eclipse, or VS Code.
  • Run:

mvn clean install


3️ Configure the Database (application.properties)

Modify src/main/resources/application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/employee_db

spring.datasource.username=root

spring.datasource.password=yourpassword

spring.jpa.hibernate.ddl-auto=update

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

server.port=8080

📌 Make sure MySQL is running and replace yourpassword with your actual MySQL password.


4️ Create the Employee Model (JPA Entity)

Create a new Java class inside com.example.model:

package com.example.model;

import jakarta.persistence.*;

@Entity

@Table(name = "employees")

public class Employee {

    @Id

    @GeneratedValue(strategy = GenerationType.IDENTITY)

    private Long id;   

    private String name;

    private String department;

    private double salary;

    // Getters and Setters

}


5️ Create the Repository Layer

Create EmployeeRepository.java inside com.example.repository:

package com.example.repository;

import com.example.model.Employee;

import org.springframework.data.jpa.repository.JpaRepository;

 

public interface EmployeeRepository extends JpaRepository<Employee, Long> {

}

Spring Data JPA provides built-in database methods like findAll(), save(), deleteById(), etc.


6️ Create the Service Layer

Create EmployeeService.java inside com.example.service:

package com.example.service;

import com.example.model.Employee;

import com.example.repository.EmployeeRepository;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class EmployeeService {

    @Autowired

    private EmployeeRepository repository;

    public List<Employee> getAllEmployees() {

        return repository.findAll();

    }

    public Employee saveEmployee(Employee employee) {

        return repository.save(employee);

    }

    public void deleteEmployee(Long id) {

        repository.deleteById(id);

    }

}


7️ Create the Controller Layer

Create EmployeeController.java inside com.example.controller:

package com.example.controller;

import com.example.model.Employee;

import com.example.service.EmployeeService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

 

@RestController

@RequestMapping("/employees")

public class EmployeeController {

    @Autowired

    private EmployeeService employeeService;

    @GetMapping

    public List<Employee> getAllEmployees() {

        return employeeService.getAllEmployees();

    }

    @PostMapping

    public Employee createEmployee(@RequestBody Employee employee) {

        return employeeService.saveEmployee(employee);

    }

    @DeleteMapping("/{id}")

    public void deleteEmployee(@PathVariable Long id) {

        employeeService.deleteEmployee(id);

    }

}

This provides a REST API for managing employees.


8️ Run the Spring Boot Application

Run the main class EmployeeManagementApplication.java:

package com.example;

 

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

public class EmployeeManagementApplication {

    public static void main(String[] args) {

SpringApplication.run(EmployeeManagementApplication.class, args);

    }

}

Now, start the project using:

mvn spring-boot:run

Your application will run on http://localhost:8080/employees.


🔹 Testing the APIs

Use Postman or cURL to test the APIs.

1️ Get All Employees

curl -X GET http://localhost:8080/employees

2️ Create a New Employee

curl -X POST http://localhost:8080/employees -H "Content-Type: application/json" -d '{

  "name": "John Doe",

  "department": "IT",

  "salary": 50000

}'

3️ Delete an Employee

curl -X DELETE http://localhost:8080/employees/1


🎯 Conclusion

🔹 Spring Boot makes Java web development easier by handling backend logic, database connectivity, and REST APIs.
🔹 In the Employee Management System, Spring Boot provides a scalable and maintainable architecture.
🔹 We used Spring Data JPA, MySQL, and Spring Web to build the backend.

🔹 What is MySQL?

MySQL is a popular relational database management system (RDBMS) used for storing and managing structured data. It is open-source, fast, and reliable, making it ideal for web applications and enterprise systems.

Key Features of MySQL

  • Scalability – Handles large datasets efficiently.
  • ACID Compliance – Ensures data integrity and transaction safety.
  • High Performance – Optimized for speed and efficiency.
  • Cross-Platform – Works on Windows, macOS, and Linux.
  • Secure – Provides user authentication and access control.

🔹 Why Use MySQL in Employee Management System?

In the Employee Management System, MySQL is used to:

  • Store employee data (name, department, salary, etc.).
  • Handle CRUD operations (Create, Read, Update, Delete).
  • Work with Spring Boot and JPA for seamless database integration.

🔹 Setting Up MySQL for Spring Boot Project

1️ Install MySQL

  • Download from MySQL Official Website
  • Install MySQL Server and MySQL Workbench (optional for GUI management).
  • Start the MySQL service.

2️ Create a New Database

Run the following SQL command in MySQL Workbench or the command line:

CREATE DATABASE employee_db;

📌 Ensure MySQL is running on port 3306 (default).


3️ Configure MySQL in Spring Boot

Edit src/main/resources/application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/employee_db

spring.datasource.username=root

spring.datasource.password=yourpassword

spring.jpa.hibernate.ddl-auto=update

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

📌 Replace yourpassword with your actual MySQL password.


4️ Create Employee Table (Automatically Handled by JPA)

Spring Boot auto-generates tables based on the Employee entity:

@Entity

@Table(name = "employees")

public class Employee {

    @Id

    @GeneratedValue(strategy = GenerationType.IDENTITY)

    private Long id;

    private String name;

    private String department;

    private double salary;

}

📌 No need to manually create tables if spring.jpa.hibernate.ddl-auto=update is set.


5️ Verify MySQL Connection

Run the project:

mvn spring-boot:run

Check in MySQL Workbench:

SELECT * FROM employees;

Employee records should be visible in the database!


🎯 Conclusion

  • MySQL stores and manages structured employee data.
  • It integrates seamlessly with Spring Boot using Spring Data JPA.
  • CRUD operations in Spring Boot directly interact with MySQL.

🔹 What is Maven?

Apache Maven is a build automation and dependency management tool for Java projects. It helps developers manage project builds, dependencies, and plugins efficiently.

Key Features of Maven

  • Dependency Management – Automatically downloads required libraries from a central repository.
  • Build Automation – Simplifies compiling, packaging, and deploying Java applications.
  • Project Structure Standardization – Uses a convention-over-configuration approach.
  • Plugins & Extensions – Supports additional tools for testing, documentation, and deployment.

🔹 Why Use Maven in Employee Management System?

In the Employee Management System, Maven helps to:

  • Manage dependencies like Spring Boot, MySQL Connector, and JPA.
  • Automate the build process (compile, test, package, and run the project).
  • Ensure project portability and consistency across different environments.

🔹 How to Use Maven in the Project?

1️ Install Maven (If Not Installed)

  • Windows: Download from Maven Official Website and add it to the system PATH.
  • Linux/macOS: Install via package manager:

sudo apt install maven  # Ubuntu/Debian

brew install maven      # macOS

  • Verify installation:

mvn -version


2️ Create a Spring Boot Project with Maven

Use Spring Initializr (recommended) to generate a Maven-based project:

  • Go to Spring Initializr
  • Select:
    • Project: Maven
    • Language: Java
    • Spring Boot Version: Latest stable
    • Dependencies: Spring Web, Spring Data JPA, MySQL Driver
  • Click Generate and extract the ZIP file.

3️ Understanding the pom.xml File (Maven Configuration)

The pom.xml file defines:

  • Project metadata (name, version, description).
  • Dependencies (external libraries like Spring Boot, MySQL).
  • Plugins (for build and testing).

Example pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0

    http://maven.apache.org/xsd/maven-4.0.0.xsd">

   

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>

    <artifactId>employee-management</artifactId>

    <version>1.0.0</version>

    <packaging>jar</packaging>

 

    <dependencies>

        <!-- Spring Boot Starter for Web -->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

 

        <!-- Spring Boot Starter for JPA (Database ORM) -->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-data-jpa</artifactId>

        </dependency>

 

        <!-- MySQL Database Connector -->

        <dependency>

            <groupId>mysql</groupId>

            <artifactId>mysql-connector-java</artifactId>

        </dependency>

 

        <!-- Spring Boot Testing -->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-test</artifactId>

            <scope>test</scope>

        </dependency>

    </dependencies>

 

    <build>

        <plugins>

            <!-- Maven Compiler Plugin -->

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-compiler-plugin</artifactId>

                <version>3.8.1</version>

                <configuration>

                    <source>17</source>

                    <target>17</target>

                </configuration>

            </plugin>

        </plugins>

    </build>

</project>

📌 Key Sections in pom.xml:

  • <dependencies> – Defines libraries needed for the project.
  • <build> – Specifies compilation and plugins.
  • <version> – Defines the Java version compatibility.

4️ Running the Project Using Maven

Once dependencies are configured:

  • Compile the project:

mvn clean compile

  • Run the Spring Boot Application:

mvn spring-boot:run

  • Package into a JAR file:

mvn clean package

  • Run the JAR file:

java -jar target/employee-management-1.0.0.jar


🎯 Conclusion

  • Maven simplifies dependency management and builds in Java projects.
  • It automates compiling, testing, and packaging.
  • Spring Boot projects use Maven to fetch required libraries effortlessly.

🔹 What is Postman?

Postman is a powerful API testing tool that helps developers build, test, and document APIs efficiently. It provides an easy-to-use interface to send requests to APIs and inspect responses.


🔹 Why Use Postman in Employee Management System?

When developing a Spring Boot-based Employee Management System, the backend exposes REST APIs for operations like:

  • Adding an employee (POST /employees)
  • Fetching employees (GET /employees)
  • Updating employee details (PUT /employees/{id})
  • Deleting an employee (DELETE /employees/{id})

Postman helps by: Testing APIs without writing a frontend.
Validating request and response formats.
Debugging backend issues faster.


🔹 How to Use Postman for API Testing?

1️ Install Postman

  • Download from Postman Official Website
  • Install it on Windows, macOS, or Linux.

2️ Test APIs in Postman

Once your Spring Boot application is running (mvn spring-boot:run), test the APIs:

🔹 Example: Testing Employee Management APIs

1️ Test POST /employees (Create an Employee)

  • Open Postman.
  • Select POST.
  • Enter URL: http://localhost:8080/employees
  • Go to Body → Select raw → Choose JSON.
  • Enter the request body:

{

  "name": "John Doe",

  "email": "john.doe@example.com",

  "position": "Software Engineer"

}

  • Click Send.
  • If successful, it returns a 201 Created response.

2️ Test GET /employees (Fetch Employees)

  • Select GET.
  • Enter URL: http://localhost:8080/employees
  • Click Send.
  • It returns a list of employees.

3️ Test PUT /employees/{id} (Update Employee)

  • Select PUT.
  • Enter URL: http://localhost:8080/employees/1
  • Go to Body → Select raw → Choose JSON.
  • Enter:

{

  "name": "John Doe",

  "email": "john.doe@company.com",

  "position": "Senior Developer"

}

  • Click Send.

4️ Test DELETE /employees/{id} (Delete Employee)

  • Select DELETE.
  • Enter URL: http://localhost:8080/employees/1
  • Click Send.

🎯 Conclusion

  • Postman simplifies API testing in your Employee Management System.
  • It helps validate API requests and responses without needing a frontend.
  • You can save requests for future testing and debugging.

🔹 What is an IDE?

An IDE (Integrated Development Environment) is a software application that provides a complete environment for coding, debugging, and managing software projects. It includes:
A code editor (for writing code)
A compiler/interpreter (for running code)
Debugging tools (to find and fix errors)
Version control support (e.g., Git)


🔹 Popular IDEs for Java Development

When developing a Spring Boot Employee Management System, you can use any of the following IDEs:

1️ IntelliJ IDEA (Recommended for Spring Boot)

Developed by: JetBrains
Best for: Java & Spring Boot development
Features:

  • Smart code suggestions
  • Built-in Spring Boot support
  • Advanced debugging tools
  • Integrated Maven and Gradle
    Download: IntelliJ IDEA

2️ Eclipse (Popular for Java)

Developed by: Eclipse Foundation
Best for: General Java development
Features:

  • Open-source and free
  • Supports Java EE, Spring, and Maven
  • Customizable with plugins
    Download: Eclipse

3️ Spring Tool Suite (STS)

Developed by: VMware
Best for: Spring Boot development
Features:

  • Preconfigured for Spring Boot
  • Built-in support for Spring projects
  • Integrated Maven support
    Download: Spring Tool Suite (STS)

4️ Visual Studio Code (VS Code)

Developed by: Microsoft
Best for: Lightweight Java development
Features:

  • Fast and lightweight
  • Requires Java extensions (e.g., "Extension Pack for Java")
  • Supports Java, Node.js, and more
    Download: VS Code

🔹 Which IDE Should You Choose?

  • For beginnersSTS or Eclipse (simple setup, Spring support).
  • For professional Java developmentIntelliJ IDEA (best for large projects).
  • For lightweight developmentVS Code (requires extensions).

🎯 Conclusion

An IDE helps you write, debug, and manage your Java code efficiently. If you’re developing a Spring Boot-based Employee Management System, I recommend using IntelliJ IDEA or STS for the best experience.

 

 

How to Use IntelliJ IDEA (Community Edition) for Spring Boot Development 🚀

Since you're developing an Employee Management System using Spring Boot, JSP, and MySQL, IntelliJ IDEA is a great choice. Here’s a step-by-step guide to setting up and running your Spring Boot project.


🔹 Step 1: Download and Install IntelliJ IDEA

1️ Download IntelliJ IDEA (Community Edition)

2️ Install IntelliJ IDEA

  • Run the installer and follow the setup instructions
  • During installation, select:
    • Java Development
    • Maven & Gradle (for dependency management)
    • Spring Boot Plugin (optional, but useful)

🔹 Step 2: Install Java Development Kit (JDK 21)

Since your Java version is 21.0.1 (LTS), you don't need to install a new JDK.
If you haven't installed Java, download it from:
🔗 JDK 21 Download


🔹 Step 3: Create a New Spring Boot Project in IntelliJ IDEA

Method 1: Using Spring Initializr (Recommended)

1️ Open IntelliJ IDEA
2️
Click on "New Project"
3️
Select Spring Initializr
4️
Configure project settings:

  • Project SDK: Select Java 21
  • Language: Java
  • Spring Boot Version: Choose latest stable (e.g., 3.x.x)
  • Project Name: employee-management
  • Group ID: com.example
  • Artifact ID: employee-management

5️ Click Next and add dependencies:

  • Spring Web (for REST APIs & Controllers)
  • Spring Data JPA (for database interaction)
  • MySQL Driver (for database connection)
  • Spring Boot Dev Tools(Provide Live reload for first development.
  • Lombok (to reduce boilerplate code)
  • Tomcat Embed Jasper (to support JSP)
  • JSTL (for JSP tag library)

6️ Click Finish → IntelliJ IDEA will download and set up your project 🚀


Method 2: Import an Existing Spring Boot Project

If you created your project using Spring Initializr online (start.spring.io):
1️
Open IntelliJ IDEA
2️
Click Open Project
3️
Select your project folder (employee-management)
4️
IntelliJ will detect pom.xml and ask to import dependencies → Click Import
5️
Wait for dependencies to load and start coding!


🔹 Step 4: Configure MySQL Database in application.properties

1️ Open src/main/resources/application.properties
2️
Add your MySQL database connection details:

spring.datasource.url=jdbc:mysql://localhost:3306/employee_db

spring.datasource.username=root

spring.datasource.password=yourpassword

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

 

# JPA settings

spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect

spring.jpa.hibernate.ddl-auto=update

spring.jpa.show-sql=true

📌 Note: Replace yourpassword with your actual MySQL password.


🔹 Step 5: Run the Spring Boot Application

1️ Open EmployeeManagementApplication.java (inside src/main/java/com/example/employee-management/)
2️
Click Run or use Shift + F10
3️
If successful, you’ll see:

nginx

CopyEdit

Tomcat started on port 8080

Application started successfully!

🚀 Now, your Spring Boot project is running at:
🔗 http://localhost:8080


🔹 Step 6: Create Employee Entity & Repository

Create an Entity Class: Employee.java
📂 src/main/java/com/example/employee-management/model/Employee.java

java

CopyEdit

package com.example.employee_management.model;

 

import jakarta.persistence.*;

import lombok.Data;

 

@Entity

@Data

@Table(name = "employees")

public class Employee {

    @Id

    @GeneratedValue(strategy = GenerationType.IDENTITY)

    private Long id;

 

    @Column(nullable = false)

    private String name;

 

    @Column(nullable = false, unique = true)

    private String email;

 

    @Column(nullable = false)

    private String department;

}

Create Repository Interface: EmployeeRepository.java
📂 src/main/java/com/example/employee-management/repository/EmployeeRepository.java

java

CopyEdit

package com.example.employee_management.repository;

 

import org.springframework.data.jpa.repository.JpaRepository;

import com.example.employee_management.model.Employee;

 

public interface EmployeeRepository extends JpaRepository<Employee, Long> {

}


🔹 Step 7: Create Controller and JSP View

Create Controller: EmployeeController.java
📂 src/main/java/com/example/employee-management/controller/EmployeeController.java

java

CopyEdit

package com.example.employee_management.controller;

 

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.GetMapping;

import com.example.employee_management.repository.EmployeeRepository;

 

@Controller

public class EmployeeController {

    private final EmployeeRepository employeeRepository;

 

    public EmployeeController(EmployeeRepository employeeRepository) {

        this.employeeRepository = employeeRepository;

    }

 

    @GetMapping("/employees")

    public String listEmployees(Model model) {

        model.addAttribute("employees", employeeRepository.findAll());

        return "employees";

    }

}

Create JSP File for Display: employees.jsp
📂 src/main/webapp/WEB-INF/views/employees.jsp

jsp

CopyEdit

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>

<head>

    <title>Employee List</title>

</head>

<body>

    <h2>Employee List</h2>

    <table border="1">

        <tr>

            <th>ID</th>

            <th>Name</th>

            <th>Email</th>

            <th>Department</th>

        </tr>

        <c:forEach var="employee" items="${employees}">

            <tr>

                <td>${employee.id}</td>

                <td>${employee.name}</td>

                <td>${employee.email}</td>

                <td>${employee.department}</td>

            </tr>

        </c:forEach>

    </table>

</body>

</html>


🔹 Step 8: Restart and Test the Application

1️ Run the Application (Shift + F10)
2️
Go to Browser:

  • 📌 http://localhost:8080/employees → Shows Employee List

🎯 Summary: What We Did

Installed IntelliJ IDEA (Community Edition)
Created a Spring Boot Project with JSP & MySQL
Configured MySQL Database
Created Employee Entity & Repository
Created Employee Controller & JSP View
Successfully Ran the Application 🚀


💡 Next Steps

1️ Add Create, Update, Delete Operations
2️
Add Bootstrap for Better UI
3️
Use Spring Security for Login (Optional)

Would you like me to help with CRUD operations next? 😊

 

Post a Comment

0Comments

Post a Comment (0)