tlias管理系统-修改部门功能实现

This commit is contained in:
2025-10-09 15:36:46 +08:00
parent cd606ccc25
commit eead8c62bd
4 changed files with 52 additions and 4 deletions

View File

@@ -53,4 +53,26 @@ public class DeptController {
deptService.add(dept); deptService.add(dept);
return Result.success(); 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();
}
} }

View File

@@ -1,10 +1,7 @@
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.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
@@ -22,4 +19,12 @@ public interface DeptMapper {
@Insert("insert into dept (name, create_time, update_time) " + @Insert("insert into dept (name, create_time, update_time) " +
"VALUES (#{name},#{createTime},#{updateTime})") "VALUES (#{name},#{createTime},#{updateTime})")
void insert(Dept dept); void insert(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);
} }

View File

@@ -13,4 +13,10 @@ public interface DeptService {
//新增部门 //新增部门
void add(Dept dept); void add(Dept dept);
//根据id查询部门
Dept getDeptById(Integer id);
//根据id更新部门
void update(Dept dept);
} }

View File

@@ -36,4 +36,19 @@ public class DeptServiceImpl implements DeptService {
dept.setUpdateTime(LocalDateTime.now()); dept.setUpdateTime(LocalDateTime.now());
deptMapper.insert(dept); deptMapper.insert(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);
}
} }