1 根据id查询员工信息
1.1 EmployeeController中添加方法,接收前端提交过来的数据
@GetMapping("/{id}")
@ApiOperation("根据id查询员工信息")
public Result<Employee> getById(@PathVariable Long id){
Employee employee = employeeService.getById(id);
return Result.success(employee);
}
1.2 getById(id)方法扩展到employeeService接口中
Employee getById(Long id);
1.3 employeeService接口的实现类实现getById(id)方法
public Employee getById(Long id) {
Employee employee = employeeMapper.getById(id);
employee.setPassword("****");
return employee;
}
1.4 employeeMapper中实现getById(id)
@Select("select * from employee where id = #{id}")
Employee getById(Long id)
2 编辑员工信息
2.1 EmployeeController中添加方法,接收前端提交过来的数据
@PutMapping
@ApiOperation("编辑询员工信息")
public Result update(@RequestBody EmployeeDTO employeeDTO) {
log.info("编辑员工信息:{}", employeeDTO);
employeeService.update(employeeDTO);
return Result.success();
}
2.2 employeeService.update(employeeDTO)方法扩展到employeeService接口中
void update(EmployeeDTO employeeDTO);
2.3 employeeService接口的实现类实现employeeService.update(employeeDTO)方法
public void update(EmployeeDTO employeeDTO) {
Employee employee = new Employee();
BeanUtils.copyProperties(employeeDTO, employee);
employee.setUpdateTime(LocalDateTime.now());
employee.setUpdateUser(BaseContext.getCurrentId());
employeeMapper.update(employee);
}
2.4 调用Mapper修改数据库
- 之前写启用禁用员工账号的时候写的update,就是根据主键动态修改属性,可以复用
- void update(Employee employee)之前写的