Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views7 pages

Week 7 8 and 9 Assignment

The document outlines the development of an Employee Leave Management System using Spring MVC and JdbcTemplate, allowing employees to apply for, view, and cancel leave requests, while enabling admins to manage these requests. It includes the architecture details, configuration files, model classes, DAO, service, and controller implementations. The application utilizes MySQL for database management and JSP for the view layer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Week 7 8 and 9 Assignment

The document outlines the development of an Employee Leave Management System using Spring MVC and JdbcTemplate, allowing employees to apply for, view, and cancel leave requests, while enabling admins to manage these requests. It includes the architecture details, configuration files, model classes, DAO, service, and controller implementations. The application utilizes MySQL for database management and JSP for the view layer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Employee Leave Management System

Problem Statement:

Develop a web application using Spring MVC with JdbcTemplate where


employees can:
 Apply for leave
 View applied leave history
 Cancel their leave request
The admin can:
 View all leave requests
 Approve or reject leave applications

Architecture:
 Spring MVC – for the controller and web layer
 JdbcTemplate – for database interaction
 Model – simple POJOs for Employee and Leave
 MySQL – as the database
 JSP – as the view technology
Source code :

// Project: Employee Leave Management System

// Stack: Spring MVC, JdbcTemplate, JSP, MySQL

// ---- CONFIGURATION FILE ----

// config/WebAppConfig.java

package config;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import org.springframework.jdbc.datasource.DriverManagerDataSource;

import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.sql.DataSource;

@Configuration

@EnableWebMvc

@ComponentScan(basePackages = "controller")

public class WebAppConfig {

@Bean

public InternalResourceViewResolver viewResolver() {

InternalResourceViewResolver resolver = new InternalResourceViewResolver();

resolver.setPrefix("/views/");

resolver.setSuffix(".jsp");

return resolver;

@Bean

public DataSource dataSource() {

DriverManagerDataSource dataSource = new DriverManagerDataSource();

dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");

dataSource.setUrl("jdbc:mysql://localhost:3306/leave_management");

dataSource.setUsername("root");

dataSource.setPassword("password");

return dataSource;

// ---- MODEL CLASSES ----

// model/Employee.java

package model;
public class Employee {

private int id;

private String name;

// Getters and Setters

// model/LeaveRequest.java

package model;

import java.util.Date;

public class LeaveRequest {

private int id;

private int employeeId;

private Date startDate;

private Date endDate;

private String reason;

private String status;

// Getters and Setters

// ---- DAO CLASS ----

// dao/LeaveDAO.java

package dao;

import model.LeaveRequest;

import java.util.List;

public interface LeaveDAO {

void applyLeave(LeaveRequest leave);


List<LeaveRequest> getLeaveHistory(int employeeId);

List<LeaveRequest> getAllLeaveRequests();

void updateLeaveStatus(int leaveId, String status);

void cancelLeave(int leaveId);

// ---- SERVICE CLASS ----

// service/LeaveService.java

package service;

import dao.LeaveDAO;

import model.LeaveRequest;

import java.util.List;

public class LeaveService {

private LeaveDAO leaveDAO;

public void setLeaveDAO(LeaveDAO leaveDAO) {

this.leaveDAO = leaveDAO;

public void applyLeave(LeaveRequest leave) {

leaveDAO.applyLeave(leave);

public List<LeaveRequest> getLeaveHistory(int employeeId) {

return leaveDAO.getLeaveHistory(employeeId);

public List<LeaveRequest> getAllLeaveRequests() {

return leaveDAO.getAllLeaveRequests();

}
public void updateLeaveStatus(int leaveId, String status) {

leaveDAO.updateLeaveStatus(leaveId, status);

public void cancelLeave(int leaveId) {

leaveDAO.cancelLeave(leaveId);

// ---- CONTROLLER ----

// controller/LeaveController.java

package controller;

import model.LeaveRequest;

import service.LeaveService;

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

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

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

import java.util.List;

@Controller

public class LeaveController {

@Autowired

private LeaveService leaveService;

@GetMapping("/apply")

public String showApplyForm() {

return "applyLeave";

@PostMapping("/apply")
public String applyLeave(@ModelAttribute LeaveRequest leave) {

leave.setStatus("Pending");

leaveService.applyLeave(leave);

return "redirect:/history";

@GetMapping("/history")

public String viewHistory(Model model) {

List<LeaveRequest> history = leaveService.getLeaveHistory(1); // Static ID for demo

model.addAttribute("history", history);

return "leaveHistory";

@GetMapping("/admin")

public String adminDashboard(Model model) {

List<LeaveRequest> all = leaveService.getAllLeaveRequests();

model.addAttribute("requests", all);

return "adminDashboard";

@PostMapping("/admin/update")

public String updateStatus(@RequestParam int id, @RequestParam String status) {

leaveService.updateLeaveStatus(id, status);

return "redirect:/admin";

@PostMapping("/cancel")

public String cancelLeave(@RequestParam int id) {

leaveService.cancelLeave(id);

return "redirect:/history";

You might also like