启用禁用员工账号
1.EmployeeController接收前端提交过来的数据
@PostMapping("/status/{status}")
@ApiOperation("启用禁用员工账号")
public Result startOrStop(@PathVariable Integer status, Long id){
log.info("启用禁用员工账号:{}, {}", status, id);
employeeService.StartOrStop(status, id);
return Result.success();
}
2.EmployeeService接口下添加StartOrStop方法
void StartOrStop(Integer status, Long id);
3.EmployeeService接口的实现类下实现方法
public void StartOrStop(Integer status, Long id) {
Employee employee = Employee.builder()
.status(status)
.id(id).build();
employeeMapper.update(employee);
}
4.EmployeeMapper.java添加updae方法
void update(Employee employee);
5.EmployeeMapper.xml添加update动态语句
<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>