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 0fd522f..42f4634 100644 --- a/tlias-web/src/main/java/com/inmind/controller/DeptController.java +++ b/tlias-web/src/main/java/com/inmind/controller/DeptController.java @@ -53,5 +53,25 @@ public class DeptController { return Result.success(); } + /* + 根据部门id查询部门数据(点击编辑时,内容回显) + */ + @GetMapping("/{id}") + public Result getDeptById(@PathVariable Integer id){ + log.info("查询部门:id--{}",id); + //调用业务层,获取部门数据 + Dept dept = deptService.getDeptById(id); + return Result.success(dept); + } + /* + 根据id修改部门 + */ + @PutMapping + public Result update(@RequestBody Dept dept){ + log.info("更新部门:{}",dept); + //调用业务层更新部门名称 + deptService.update(dept); + 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 0d6980c..c2213dd 100644 --- a/tlias-web/src/main/java/com/inmind/mapper/DeptMapper.java +++ b/tlias-web/src/main/java/com/inmind/mapper/DeptMapper.java @@ -1,10 +1,7 @@ package com.inmind.mapper; 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.Select; +import org.apache.ibatis.annotations.*; import java.util.List; @@ -19,4 +16,12 @@ public interface DeptMapper { @Insert("insert into dept (name, create_time, update_time) values " + "(#{name},#{createTime},#{updateTime})") void addDept(Dept dept); + + //根据id查询部门 + @Select("select * from dept where id = #{id}") + Dept getDeptById(Integer id); + + //根据id更新部门名称 + @Update("update dept set name = #{name},update_time = #{updateTime} where id = #{id} ") + void update(Dept dept); } 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 5646679..47a3636 100644 --- a/tlias-web/src/main/java/com/inmind/service/DeptService.java +++ b/tlias-web/src/main/java/com/inmind/service/DeptService.java @@ -23,4 +23,11 @@ public interface DeptService { * @param dept 部门信息 */ void addDept(Dept dept); + + + //根据id查询部门 + Dept getDeptById(Integer id); + + //根据id更新部门 + void update(Dept dept); } 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 522e777..581a31f 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 @@ -45,4 +45,20 @@ public class DeptServiceImpl implements DeptService { //2.调用mapper的新增功能 deptMapper.addDept(dept); } + + + @Override + public Dept getDeptById(Integer id) { + //调用Mapper查询部门数据即可 + Dept dept = deptMapper.getDeptById(id); + return dept; + } + + @Override + public void update(Dept dept) { + //补充更新时间数据 + dept.setUpdateTime(LocalDateTime.now()); + //调用mapper更新部门 + deptMapper.update(dept); + } }