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

This commit is contained in:
xx
2026-10-27 17:06:06 +08:00
parent b019b51663
commit 062e76e931
4 changed files with 52 additions and 4 deletions
@@ -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();
}
}
@@ -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);
}
@@ -23,4 +23,11 @@ public interface DeptService {
* @param dept 部门信息
*/
void addDept(Dept dept);
//根据id查询部门
Dept getDeptById(Integer id);
//根据id更新部门
void update(Dept dept);
}
@@ -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);
}
}