首页>代码>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); } }


15578157792 LV7
4月25日
dane168 LV8
2月17日
Long1022gnoL
1月17日
暂无贡献等级
依旧原地徘徊 LV12
1月16日
krispeng LV15
2024年11月24日
TY0165 LV20
2024年6月24日
颜菜菜 LV2
2024年6月19日
计科一班 LV7
2024年6月19日
17380184110
2024年6月18日
暂无贡献等级
xin xie LV1
2024年6月13日