对于修改连接的uri
在list.html中
修改需要知道id,所以路径上需要有有该修改的员工id
两个属性是要进行拼串的不可以写在一起
controller实现页面的跳转
//修改@GetMapping("/update/{id}")public String updataEmp(@PathVariable("id")Integer id, Model model){ Employee employee = employeeDao.get(id); model.addAttribute("emp",employee); //部门选择的修改 Collectiondepartments = departmentDao.getDepartments(); model.addAttribute("depts",departments); return "emp/update";}
在add.html文件夹中复制并且命名为update.html
注意使用的RESTFUL方式,使用put请求时的隐藏域以及id的隐藏域
对数据进行的回显判断操作
实现页面修改的controller:
//员工修改@PutMapping("/update1")public String updataToEmp(Employee employee){ System.out.println(employee); //修改的数据 employeeDao.save(employee); return "redirect:/emps";}
此时可以成功添加数据 修改数据
在删除页面的标志:
list.html中
controller实现:
//删除请求@DeleteMapping("/delete/{id}")public String delete(@PathVariable("id") Integer id){ employeeDao.delete(id); return "redirect:/emps";}