1.19
跟着视频案例敲代码,来熟悉springboot框架
今天完成部门管理中的删除功能
@Slf4j @RestController public class DeptController { @Autowired private DeptService deptService; @DeleteMapping("/depts/{id}") public Result delete(@PathVariable Integer id) { //日志记录 log.info("根据id删除部门"); //调用service层功能 deptService.delete(id); //响应 return Result.success(); } }
public interface DeptService { /** * 根据id删除部门 * @param id 部门id */ void delete(Integer id); }
@Slf4j @Service public class DeptServiceImpl implements DeptService { @Autowired private DeptMapper deptMapper; @Override public void delete(Integer id) { //调用持久层删除功能 deptMapper.deleteById(id); } //省略... }
@Mapper public interface DeptMapper { /** * 根据id删除部门信息 * @param id 部门id */ @Delete("delete from dept where id = #{id}") void deleteById(Integer id); //省略... }