tlias管理系统--部门管理--删除部门&新增部门
This commit is contained in:
@@ -7,10 +7,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -36,4 +33,19 @@ public class DeptController {
|
|||||||
List<Dept> deptList = deptService.getDeptList();
|
List<Dept> deptList = deptService.getDeptList();
|
||||||
return Result.success(deptList);
|
return Result.success(deptList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/depts/{id}")
|
||||||
|
public Result delete(@PathVariable Integer id){
|
||||||
|
log.info("删除部门:{}",id);
|
||||||
|
deptService.delete(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/depts")
|
||||||
|
public Result add(@RequestBody Dept dept){
|
||||||
|
log.info("新增部门:{}",dept);
|
||||||
|
deptService.add(dept);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.inmind.mapper;
|
package com.inmind.mapper;
|
||||||
|
|
||||||
import com.inmind.pojo.Dept;
|
import com.inmind.pojo.Dept;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
@@ -10,4 +12,11 @@ import java.util.List;
|
|||||||
public interface DeptMapper {
|
public interface DeptMapper {
|
||||||
@Select("select * from dept")
|
@Select("select * from dept")
|
||||||
List<Dept> getDeptList();
|
List<Dept> getDeptList();
|
||||||
|
|
||||||
|
@Delete("delete from dept where id = #{id}")
|
||||||
|
void delete(Integer id);
|
||||||
|
|
||||||
|
//insert into dept (name,create_time,update_time) values ()
|
||||||
|
@Insert("insert into dept (name,create_time,update_time) values (#{name},#{createTime},#{updateTime})")
|
||||||
|
void insert(Dept dept);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,17 @@ public interface DeptService {
|
|||||||
查询所有部门的信息
|
查询所有部门的信息
|
||||||
*/
|
*/
|
||||||
List<Dept> getDeptList();
|
List<Dept> getDeptList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除部门
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void delete(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增部门
|
||||||
|
* @param dept
|
||||||
|
*/
|
||||||
|
void add(Dept dept);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -24,4 +25,23 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
List<Dept> deptList = deptMapper.getDeptList();
|
List<Dept> deptList = deptMapper.getDeptList();
|
||||||
return deptList;
|
return deptList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除部门
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delete(Integer id) {
|
||||||
|
deptMapper.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Dept dept) {
|
||||||
|
//准备基础数据
|
||||||
|
dept.setCreateTime(LocalDateTime.now());
|
||||||
|
dept.setUpdateTime(LocalDateTime.now());
|
||||||
|
//调用mapper新增部门
|
||||||
|
deptMapper.insert(dept);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user