苍穹外卖项目学习日记(3)

苍穹外卖项目学习日记(3) day02-2

启用禁用员工账号

  • controll层新增相应方法
  • EmployeeController.java
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用员工账号")
    public Result startOrStop(@PathVariable Integer status,Long id){
        log.info("启用禁用员工账号:{},{}",status,id);
        employeeService.startOrStop(status,id);
        return Result.success();
    }
  • service也添加相应方法,并且在实现类中实现
  • EmployeeServiceImpl.java
    @Override
    public void startOrStop(Integer status, Long id) {
        Employee employee = Employee.builder()
                        .status(status)
                        .id(id)
                        .build();
        employeeMapper.update(employee);
    }
  • mapper层添加方法,并且在xml文件中添加update方法
  • EmployeeMapper.xml
    <update id="update" parameterType="com.sky.entity.Employee">
        update employee
        <set>
            <if test="name != null">name = #{name},</if>
            <if test="username != null">username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="idNumber != null">id_Number = #{idNumber},</if>
            <if test="updateTime != null">update_Time = #{updateTime},</if>
            <if test="updateUser != null">update_User = #{updateUser},</if>
            <if test="status != null">status = #{status},</if>
        </set>
        where id = #{id}
    </update>

编辑员工

  • controll层新增getById相应方法,即根据员工id查询员工
  • EmployeeController.java
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询员工信息")
    public Result<Employee> getById(@PathVariable Long id){
        log.info("根据id查询员工信息:{}",id);
        Employee employee = employeeService.getById(id);
        return Result.success(employee);
    }
  • service也添加相应方法,并且在实现类中实现
  • EmployeeServiceImpl.java
    @Override
    public Employee getById(Long id) {
        Employee employee = employeeMapper.getById(id);
        employee.setPassword("******");
        return employee;
    }

  • EmployeeMapper层添加相应方法
    @Select("select * from employee where id = #{id}")
    Employee getById(Long id);
  • 下面添加编辑员工功能,* 在controll层新增update相应方法
  • EmployeeController.java
    @PutMapping
    @ApiOperation("编辑员工信息")
    public Result update(@RequestBody EmployeeDTO employeeDTO){
        log.info("编辑员工信息:{}",employeeDTO);
        employeeService.update(employeeDTO);
        return Result.success();
    }
  • service也添加相应方法,并且在实现类中实现
  • EmployeeServiceImpl.java
    @Override
    public void update(EmployeeDTO employeeDTO) {
        Employee employee = new Employee();
        BeanUtils.copyProperties(employeeDTO,employee);
        employee.setUpdateTime(LocalDateTime.now());
        employee.setUpdateUser(BaseContext.getCurrentId());
        employeeMapper.update(employee);
    }
  • 最后按照视频教程导入分类管理即可

你可能感兴趣的:(苍穹外卖,spring,boot,java)