黑马程序员_Java项目实战《苍穹外卖》_Day02_启用禁用员工账号、编辑员工

Day2_启用禁用员工账号

代码开发

  • 在EmployeeController类编写启用禁用员工账号方法
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用员工账号")
    public Result startOrStop(@PathVariable Integer status,Long id){
        log.info("启用禁用员工账号:{},{}",status,id);
        employeeService.startOrStop(status,id);
        return Result.success();
    }
    
  • 调用employeeService完成新增操作,在EmployeeService中扩展startOrStop方法
    void startOrStop(Integer status, Long id);
    
  • 在EmployeeServiceImpl中实现startOrStop方法
    public void startOrStop(Integer status, Long id) {
        // update employee set status = ? where id = ?
        
        /*Employee employee = new Employee();
        employee.setStatus(status);
        employee.setId(id);*/
    
        Employee employee = Employee.builder()
                .status(status)
                .id(id)
                .build();
    
        employeeMapper.update(employee);
    }
    
  • EmployeeMapper类中扩展方法
    /**
         * 根据主键动态修改属性
         * @param employee
         */
        void update(Employee employee);
    }
    
  • 在映射文件EmployeeMapper.xml中完成SQL语句的编写
    <update id="update" parameterType="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>
    

功能测试

在这里插入图片描述

将其“status”设为“0”:

刷新数据库,id=6的行status变为“0”:

在这里插入图片描述


Day2_编辑员工

需求分析和设计

产品原型
  • 进入“员工管理”页面,点击“修改”按钮

在这里插入图片描述

  • 跳转到编辑的页面,回显员工的当前信息,可根据需要修改信息

在这里插入图片描述

接口设计

由产品原型,编辑员工操作涉及到两个接口:

  • 根据id查询员工信息

在这里插入图片描述
返回数据即为员工信息的各个字段,如code、data、msg

  • 编辑员工信息

在这里插入图片描述

请求体:在这里插入图片描述

返回数据为code、data、msg

代码开发

  • 在EmployeeController类编写方法
    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询员工信息")
    public Result<Employee> getById(@PathVariable Long id){
        Employee employee = employeeService.getById(id);
        return Result.success(employee);
    }
    
    /**
     * 编辑员工信息
     * @param employeeDTO
     * @return
     */
    @PutMapping
    @ApiOperation("编辑员工信息")
    public Result update(@RequestBody EmployeeDTO employeeDTO){
        log.info("编辑员工信息:{}",employeeDTO);
        employeeService.update(employeeDTO);
        return Result.success();
    }
    
  • 调用employeeService完成操作,在EmployeeService中扩展方法
    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    Employee getById(Long id);
    
    /**
     * 编辑员工信息
     * @param employeeDTO
     */
    void update(EmployeeDTO employeeDTO);
    
  • 在EmployeeServiceImpl中实现方法
    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    public Employee getById(Long id) {
        Employee employee = employeeMapper.getById(id);
        employee.setPassword("****");
        return employee;
    }
    
    /**
     * 编辑员工信息
     * @param 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);
    }
    
  • EmployeeMapper类中扩展根据id查询员工信息方法
    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    @Select("select * from employee where id = #{id}")
    Employee getById(Long id);
    

功能测试

接口网址:苍穹外卖项目接口文档

  • 测试根据id查询员工信息的功能

在这里插入图片描述

  • 测试编辑员工信息的功能

在这里插入图片描述

查询数据库验证:

在这里插入图片描述


至此,苍穹外卖启禁用员工账号与编辑员工部分代码开发测试完毕。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
黑马程序员苍穹外卖项目中的Nginx配置文件可以根据具体需求进行配置。根据引用\[1\]中的描述,可以通过双击nginx.exe启动Nginx,并在http://localhost/访问前端页面。这意味着Nginx的配置文件应该包含有关前端页面的相关配置。另外,根据引用\[2\]中的描述,Nginx还可以用作反向代理和负载均衡,因此配置文件还应包含有关反向代理和负载均衡的相关配置。最后,根据引用\[3\]中的描述,苍穹外卖项目还需要与第三方配送公司进行对接和管理,因此配置文件还应包含有关与第三方配送公司对接的相关配置。综上所述,黑马程序员苍穹外卖项目的Nginx配置文件应包含前端页面的相关配置、反向代理和负载均衡的相关配置以及与第三方配送公司对接的相关配置。 #### 引用[.reference_title] - *1* [黑马程序员_Java项目实战苍穹外卖》_Day01_开发环境搭建](https://blog.csdn.net/BallerWang9/article/details/131824385)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [最适合新手的SpringBoot+SSM项目《苍穹外卖》实战—(一)项目概述](https://blog.csdn.net/qq_20185737/article/details/131575898)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值