接口-修改账号状态
1.业务需求分析
在页面上点击账号的{启用/禁用}状态,修改账号状态
2.controller代码实现,前端通过post请求将status和id传到后端,后端controller接收到这两个参数后,调用service实现类。
@PostMapping("/status/{status}")
public Result startOrstop(@PathVariable Integer status,Long id){
log.info("更新状态参数:status:{},id:{}",status,id);
employeeService.startOrstop(status,id);
return Result.success();
}
3.service实现类编写,实现类不讲这两个参数传入到mapper,而是通过builder构建起构建一个employee对象,并将这两个参数传入到这个对象中,将整个对象传入到mapper中。
public void startOrstop(Integer status, Long id) {
//通过构建器构建一个employee实体类对象
Employee employee = Employee.builder()
.status(status)
.id(id)
.build();
//将实体类对象传入update更新sql中
//update employee set status=#{status} where id=#{id}
employeeMapper.update(employee);
}
4.在sql处理中,我们通过动态sql更新employee,这个动态sql方便以后其他更新操作重复使用。