From 5fa891c93d8c854f1d8040f7342354b7095c73b7 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Wed, 28 Oct 2026 15:51:58 +0800 Subject: [PATCH] =?UTF-8?q?javaEEday10-tlias=E7=AE=A1=E7=90=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F-=E5=91=98=E5=B7=A5=E7=AE=A1=E7=90=86=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=9B=9E=E6=98=BE&=E4=BF=AE=E6=94=B9=E5=91=98?= =?UTF-8?q?=E5=B7=A5=E4=BF=A1=E6=81=AF=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/inmind/controller/EmpController.java | 22 ++++++++++++ .../java/com/inmind/mapper/EmpMapper.java | 8 +++++ .../java/com/inmind/service/EmpService.java | 6 ++++ .../inmind/service/impl/EmpServiceImpl.java | 18 ++++++++++ .../resources/com/inmind/mapper/EmpMapper.xml | 35 +++++++++++++++++++ 5 files changed, 89 insertions(+) diff --git a/tlias-web/src/main/java/com/inmind/controller/EmpController.java b/tlias-web/src/main/java/com/inmind/controller/EmpController.java index ace5359..bce7690 100644 --- a/tlias-web/src/main/java/com/inmind/controller/EmpController.java +++ b/tlias-web/src/main/java/com/inmind/controller/EmpController.java @@ -56,4 +56,26 @@ public class EmpController { empService.save(emp); return Result.success(); } + + + /* + 根据id获取员工信息 + */@GetMapping("/emps/{id}") + public Result getEmpById(@PathVariable Integer id){ + log.info("根据id获取员工信息:id:{}",id); + //调用业务层查询员工 + Emp emp = empService.getEmpById(id); + return Result.success(emp); + } + + /* + 修改员工信息 + */ + @PutMapping("/emps") + public Result updateEmp(@RequestBody Emp emp){ + log.info("修改员工信息:{}",emp); + //调用业务层查修改员工信息 + empService.updateEmp(emp); + return Result.success(); + } } diff --git a/tlias-web/src/main/java/com/inmind/mapper/EmpMapper.java b/tlias-web/src/main/java/com/inmind/mapper/EmpMapper.java index 1a37876..3618dbe 100644 --- a/tlias-web/src/main/java/com/inmind/mapper/EmpMapper.java +++ b/tlias-web/src/main/java/com/inmind/mapper/EmpMapper.java @@ -37,4 +37,12 @@ public interface EmpMapper { @Insert("insert into emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " + "values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})") void save(Emp emp); + + + + //根据id查询员工 + @Select("select * from emp where id = #{id}") + Emp getEmpById(Integer id); + + void updateEmp(Emp emp); } diff --git a/tlias-web/src/main/java/com/inmind/service/EmpService.java b/tlias-web/src/main/java/com/inmind/service/EmpService.java index 2567832..0d19649 100644 --- a/tlias-web/src/main/java/com/inmind/service/EmpService.java +++ b/tlias-web/src/main/java/com/inmind/service/EmpService.java @@ -15,4 +15,10 @@ public interface EmpService { //新增员工 void save(Emp emp); + + //根据id查询员工 + Emp getEmpById(Integer id); + + //修改员工信息 + void updateEmp(Emp emp); } diff --git a/tlias-web/src/main/java/com/inmind/service/impl/EmpServiceImpl.java b/tlias-web/src/main/java/com/inmind/service/impl/EmpServiceImpl.java index 23e96d0..377611e 100644 --- a/tlias-web/src/main/java/com/inmind/service/impl/EmpServiceImpl.java +++ b/tlias-web/src/main/java/com/inmind/service/impl/EmpServiceImpl.java @@ -69,4 +69,22 @@ public class EmpServiceImpl implements EmpService { emp.setUpdateTime(LocalDateTime.now()); empMapper.save(emp); } + + + + @Override + public Emp getEmpById(Integer id) { + //调用mapper简单查询 + Emp emp = empMapper.getEmpById(id); + return emp; + } + + //修改员工信息 + @Override + public void updateEmp(Emp emp) { + //调用mapper更新操作 + //补充基本数据 + emp.setUpdateTime(LocalDateTime.now()); + empMapper.updateEmp(emp); + } } diff --git a/tlias-web/src/main/resources/com/inmind/mapper/EmpMapper.xml b/tlias-web/src/main/resources/com/inmind/mapper/EmpMapper.xml index 8eac84b..e67fbcd 100644 --- a/tlias-web/src/main/resources/com/inmind/mapper/EmpMapper.xml +++ b/tlias-web/src/main/resources/com/inmind/mapper/EmpMapper.xml @@ -27,4 +27,39 @@ + + + update emp + + + username = #{username}, + + + password = #{password}, + + + name = #{name}, + + + gender = #{gender}, + + + image = #{image}, + + + job = #{job}, + + + entrydate = #{entrydate}, + + + dept_id = #{deptId}, + + + update_time = #{updateTime} + + + where + id = #{id}; + \ No newline at end of file