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";