- Springboot简易实战-员工列表展示及注销删除功能实现
- 一、展示员工列表
- 二、删除员工及注销功能实现兼404页面
- 1、删除员工功能
- 2、404页面
- 3、注销功能实现
在Controller层添加得到全部员工的请求,调用dao层的得到全部员工的方法:
@Controller
public class EmployeeController {
@Autowired
private EmployeeDao employeeDao;
@RequestMapping("emps")
public String getEmployees(Model model){
//得到全部的员工
Collection employees = employeeDao.getEmployees();
model.addAttribute("emps",employees);
return "emps/list";
}
}
前端接收请求:
二、删除员工及注销功能实现兼404页面 1、删除员工功能
- EmployeeController中后端请求
//删除员工
@GetMapping("/emps/del/{id}")
public String delEmp(@PathVariable Integer id){
employeeDao.delEmployee(id);
return "redirect:/emps";
}
- 前端在list.html中接收
删除2、404页面
在template目录下创建一个error文件夹,放入404.html,路径错误就会就会显示404.html页面
3、注销功能实现Dashboard Template for Bootstrap 404
- 后端注销请求:
//注销功能
@GetMapping("/signOut")
public String signOut(HttpSession session){
session.removeAttribute("userName");
return "redirect:/index";
}
- 前端接收请求:
userName



