COS315 Java Homework4 KHH200
COS315 Java Homework4 KHH200
Date:11/11/2022
Signature: Kiril Hadzhiyski
Name:Kiril Hadzhiyski
Screenshot 1 – Employee form before modification
Screenshot 2 – Employee form after modification
I’ve change the Job Title, Salary, Location and Email
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)
return "showListEmployees";
}
@RequestMapping(value="/addEmployee", method=RequestMethod.GET)
return "showAddEmployeeForm";
}
@RequestMapping(value="/addEmployeeSubmit", method=RequestMethod.POST)
/* Method to add submitted new employee details to database, and then redirect to
listEmployees */
employeeservice.save(employee);
return "redirect:/employee/listEmployees";
}
@RequestMapping(value="/editEmployee/{id}", method=RequestMethod.GET)
/* Browser request for update employee details form */
/* Employee identified by id */
public String editEmployee(@PathVariable("id") long id, Model model) {
@RequestMapping(value="/editEmployeeSubmit", method=RequestMethod.POST)
/* Update database with submitted edited employee details */
public String editEmployeeSubmit(Employee employee) {
@RequestMapping(value="/deleteEmployee/{id}", method=RequestMethod.GET)
/* Delete from database record of employee identified by id, and then redirect to
listEmployees */
public String deleteEmployee(@PathVariable("id") long id) {
@RequestMapping(value="/detailsEmployee/{id}", method=RequestMethod.GET)
Employee employee;
try {
employee = employeeservice.get(id);
}
catch (Exception a) {
employee = new Employee();
}
model.addAttribute("employee", employee);
return "showEmployeeDetails";
}
Part 2
Screenshot 1- list of the employee who have a salary of 6000.
Screenshot 5- List of all employees who have a salary greater than 5000 and live
in Sofia