员工账号启用禁用功能开发
1. 需求分析
为POST请求,提供路径参数status和id

2. 代码开发
- controller层:
java
@PostMapping("/status/{status}")
@ApiOperation(value = "启用禁用员工")
public Result startOrStop(@PathVariable Integer status,Long id){
log.info("启用禁用员工账号:{},{}",status,id);
employeeService.startOrStop(status,id);
return Result.success();
}
- service层
java
public void startOrStop(Integer status, Long id) {
Employee employee = Employee.builder().id(id).status(status).build();
employeeMapper.update(employee);
}
- mapper层(直接实现更新功能,对所有可能更新的数据进行更新)
java
void update(Employee employee);
- 动态SQL(这里直接把所有可能更新的数据写上)
xml
<update id="update">
update employee
<set>
<if test="name != null and name != ''">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="updateTime != null">updateTime = #{updateTime},</if>
<if test="idNumber != null">idNumber = #{idNumber},</if>
<if test="updateUser != null">updateUser = #{updateUser},</if>
<if test="status != null">status = #{status}</if>
</set>
where id = #{id}
</update>
3. 功能测试
Swagger测试:

前后端联调测试:

经过测试功能可以正常使用
4. 代码提交
点击Git,提交并推送
