javaEEday10-tlias-案例-部门管理-删除
This commit is contained in:
@@ -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<Dept> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Dept> deptList();
|
||||
|
||||
@Delete("delete from dept where id = #{id}")
|
||||
void deleteDept(Integer id);
|
||||
}
|
||||
|
||||
@@ -11,4 +11,10 @@ public interface DeptService {
|
||||
* @return 部门的集合
|
||||
*/
|
||||
List<Dept> deptList();
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
* @param id 部门id
|
||||
*/
|
||||
void deleteDept(Integer id);
|
||||
}
|
||||
|
||||
@@ -21,4 +21,14 @@ public class DeptServiceImpl implements DeptService {
|
||||
List<Dept> deptList = deptMapper.deptList();
|
||||
return deptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
* @param id 部门id
|
||||
*/
|
||||
@Override
|
||||
public void deleteDept(Integer id) {
|
||||
//调用dao,执行删除部门操作
|
||||
deptMapper.deleteDept(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user