首页>代码>Springboot+thymeleaf对员工的增删改查操作 带分页功能>/springboot_crm(1)/src/main/java/com/qianfeng/controller/EmployeeController.java
package com.qianfeng.controller; import com.qianfeng.dto.Page; import com.qianfeng.entity.Department; import com.qianfeng.entity.Employee; import com.qianfeng.service.DepartmentService; import com.qianfeng.service.EmployeeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; @Controller public class EmployeeController { @Autowired private EmployeeService employeeService; @Autowired private DepartmentService departmentService; /** * 获取员工列表 * @param pageNo * @param pageSize * @param model * @return */ @GetMapping(value = "/showEmployeeList") public String showEmployeeList(Integer pageNo,Integer pageSize, Model model){ if(pageNo==null){ pageNo=1; } if (pageSize==null){ pageSize=5; } Page<Employee> employees = employeeService.getEmployeePage(pageNo, pageSize); System.out.println(employees); model.addAttribute("employees",employees); return "employee_list"; } /** * 跳转添加员工页面 */ @GetMapping("/jumpAddEmployeeEdit") public String jumpAddEmployeeEdit(Model model){ List<Department> departments = departmentService.getDepartmentList(); model.addAttribute("departments", departments); return "employee_add"; } /** * 添加员工 * @param employee * @return */ @PostMapping(value = "/addEmployee") public String addEmployee(Employee employee){ employeeService.addEmployee(employee); System.out.println(employee); return "redirect:/showEmployeeList"; // return "employee_list"; } /** * 删除 * @param empId * @return */ @GetMapping(value = "/deleteEmployeeByEmpId/{empId}") public String deleteEmployeeByEmpId(@PathVariable("empId") Integer empId){ System.out.println(empId); employeeService.deleteEmployeeByEmpId(empId); return "redirect:/showEmployeeList"; } /** * 跳转更新页面 */ @GetMapping("/jumpUpdateEmployeeEdit") public String jumpUpdateEmployeeEdit(Integer empId,Model model){ //下拉列表 List<Department> departments = departmentService.getDepartmentList(); model.addAttribute("departments",departments); //数据回显 Employee employee = employeeService.getEmployeeByEmpId(empId); model.addAttribute("employee",employee); return "employee_update"; } /** * 更新员工 * @param employee * @return */ @PostMapping("/updateEmployee") public String updateEmployee(Employee employee){ System.out.println(employee); employeeService.updateEmployee(employee); return "redirect:/showEmployeeList"; } /** * JS获取分页数据 */ @ResponseBody @GetMapping(value = "/getEmployeePage") public Page<Employee> getEmployeePage(Integer pageNo,Integer pageSize){ System.out.println(pageNo); System.out.println(pageSize); if(pageNo==null){ pageNo=1; } if (pageSize==null){ pageSize=5; } return employeeService.getEmployeePage(pageNo, pageSize); } }
最近下载更多
牛牛要爆炸了 LV2
1月17日
oulingqiao LV13
2023年12月10日
601601lmy LV5
2023年10月20日
guoyan LV12
2023年10月19日
syczzxj LV9
2023年9月21日
万紫怡 LV4
2023年6月13日
遗留问题 LV2
2023年6月10日
ssh123 LV10
2023年4月18日
an1127 LV3
2023年4月4日
hbsoft2008 LV16
2023年3月10日
最近浏览更多
jay1992 LV14
3月11日
牛牛要爆炸了 LV2
1月17日
skook7 LV2
2023年12月14日
oulingqiao LV13
2023年12月10日
胡哈哈
2023年11月14日
暂无贡献等级
wsgwly LV5
2023年11月8日
abdkfksdkf LV15
2023年10月12日
syczzxj LV9
2023年9月21日
微信网友_6372890284232704 LV4
2023年8月30日
飞呀飞呀飞不放 LV7
2023年8月9日