From 9212012f06830b35212e00eb706b27a53f4de6d6 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Sun, 25 Oct 2026 14:51:54 +0800 Subject: [PATCH] =?UTF-8?q?javaEEday10-tlias-=E6=A1=88=E4=BE=8B-=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E7=AE=A1=E7=90=86-=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/inmind/controller/DeptController.java | 20 +++++++++++++------ .../java/com/inmind/mapper/DeptMapper.java | 4 ++++ .../java/com/inmind/service/DeptService.java | 6 ++++++ .../inmind/service/impl/DeptServiceImpl.java | 10 ++++++++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/tlias-web/src/main/java/com/inmind/controller/DeptController.java b/tlias-web/src/main/java/com/inmind/controller/DeptController.java index d27e92c..85a1b60 100644 --- a/tlias-web/src/main/java/com/inmind/controller/DeptController.java +++ b/tlias-web/src/main/java/com/inmind/controller/DeptController.java @@ -4,13 +4,9 @@ import com.inmind.pojo.Dept; import com.inmind.pojo.Result; import com.inmind.service.DeptService; import lombok.extern.slf4j.Slf4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; import java.util.List; @RestController @@ -23,7 +19,8 @@ public class DeptController { //logback日志框架 //private static Logger logger = LoggerFactory.getLogger("com.inmind.controller.DeptController"); - @RequestMapping("/depts") +// @RequestMapping(value = "/depts",method = {RequestMethod.GET}) + @GetMapping("/depts") public Result deptList(){ //接收请求 log.info("查询全部部门数据请求"); @@ -31,4 +28,15 @@ public class DeptController { List deptList = deptService.deptList(); return Result.success(deptList); } + +// @RequestMapping(value = "/depts/{id}",method = {RequestMethod.DELETE}) + @DeleteMapping("/depts/{id}") + //PathVariable:路径参数的注解,用来将url地址上的id参数赋值给形参id + public Result deleteDept(@PathVariable Integer id){ + log.info("删除部门:{}",id); + + //调用业务层的删除部门功能 + deptService.deleteDept(id); + return Result.success(); + } } diff --git a/tlias-web/src/main/java/com/inmind/mapper/DeptMapper.java b/tlias-web/src/main/java/com/inmind/mapper/DeptMapper.java index 273c1e1..9598e45 100644 --- a/tlias-web/src/main/java/com/inmind/mapper/DeptMapper.java +++ b/tlias-web/src/main/java/com/inmind/mapper/DeptMapper.java @@ -1,6 +1,7 @@ package com.inmind.mapper; import com.inmind.pojo.Dept; +import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; @@ -10,4 +11,7 @@ import java.util.List; public interface DeptMapper { @Select("select * from dept") List deptList(); + + @Delete("delete from dept where id = #{id}") + void deleteDept(Integer id); } diff --git a/tlias-web/src/main/java/com/inmind/service/DeptService.java b/tlias-web/src/main/java/com/inmind/service/DeptService.java index 019b027..52aefe5 100644 --- a/tlias-web/src/main/java/com/inmind/service/DeptService.java +++ b/tlias-web/src/main/java/com/inmind/service/DeptService.java @@ -11,4 +11,10 @@ public interface DeptService { * @return 部门的集合 */ List deptList(); + + /** + * 删除部门 + * @param id 部门id + */ + void deleteDept(Integer id); } diff --git a/tlias-web/src/main/java/com/inmind/service/impl/DeptServiceImpl.java b/tlias-web/src/main/java/com/inmind/service/impl/DeptServiceImpl.java index e5d7d0c..5677a96 100644 --- a/tlias-web/src/main/java/com/inmind/service/impl/DeptServiceImpl.java +++ b/tlias-web/src/main/java/com/inmind/service/impl/DeptServiceImpl.java @@ -21,4 +21,14 @@ public class DeptServiceImpl implements DeptService { List deptList = deptMapper.deptList(); return deptList; } + + /** + * 删除部门 + * @param id 部门id + */ + @Override + public void deleteDept(Integer id) { + //调用dao,执行删除部门操作 + deptMapper.deleteDept(id); + } }