0% found this document useful (0 votes)
13 views

COS315 Java Homework3

This document describes modifications made to an employee management application. It includes screenshots of adding an employee to the database, listing employees before and after adding more, the database contents, and editing an employee listing. It also shows the modified Java code for the EmployeeController, which handles requests to list, add, and view employee details. The code uses an EmployeeService to interact with the database, and redirects between pages to display the appropriate content.

Uploaded by

Craxbus K
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

COS315 Java Homework3

This document describes modifications made to an employee management application. It includes screenshots of adding an employee to the database, listing employees before and after adding more, the database contents, and editing an employee listing. It also shows the modified Java code for the EmployeeController, which handles requests to list, add, and view employee details. The code uses an EmployeeService to interact with the database, and redirects between pages to display the appropriate content.

Uploaded by

Craxbus K
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Screenshot 1 – Adding my details to the database

Screenshot 2 – List of Employees with only one entry - me

Screenshot 3 – List of Employees – all 6 entries – after adding 5


more
Screenshot 4 – H2 Database screenshot
Screenshot 5- List of employees edited

Screenshot 6 displaying the information about chosen employee

Modified code in EmployeeController.java


package edu.aubg.employees;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@SuppressWarnings("unused")
@Controller
@RequestMapping("/employee")
public class EmployeeController {

@Autowired
private EmployeeService employeeservice;

@RequestMapping(value="/listEmployees", method=RequestMethod.GET)

/* Method to show list of employees */


public String listEmployees(Model model) {

/* Get list of employees from database */


List<Employee> employeeList = employeeservice.listAll();

/* Make the list available to the view */


model.addAttribute("employees", employeeList);

return "showListEmployees";
}

/* Two methods that work in tandem */


/* to create an new employee database record */

@RequestMapping(value="/addEmployee", method=RequestMethod.GET)

/* Method to show add new employee web form */

public String addEmployee() {

/* Send web form to browser user */

return "showAddEmployeeForm";
}

@RequestMapping(value="/addEmployeeSubmit", method=RequestMethod.POST)

/* Method to add submitted new employee details to database, and then redirect to
listEmployees */

public String addEmployeeSubmit(Employee employee) {

/* Save web form data in database */


employeeservice.save(employee);

/* Finally display list of employees – including new one! */

return "redirect:/employee/listEmployees";
}

@RequestMapping(value="/detailsEmployee/{id}", method=RequestMethod.GET)

/* Show details of employee identified by id from database */


public String detailsEmployee(@PathVariable("id") long id, Model model) {

/* Get details of employee identified by id from database */

Employee employee = employeeservice.get(id);

/* Store details of this employee in model for web page */

model.addAttribute("employee", employee);

return "showEmployeeDetails";

You might also like