tlias管理系统-员工管理查询回显&修改员工信息功能实现

This commit is contained in:
2025-10-13 13:51:14 +08:00
parent 08c75b8908
commit c5541c22d4
5 changed files with 84 additions and 0 deletions

View File

@@ -52,4 +52,25 @@ 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();
}
}

View File

@@ -34,4 +34,10 @@ 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);
}

View File

@@ -15,4 +15,10 @@ public interface EmpService {
//新增员工
void save(Emp emp);
//根据id查询员工
Emp getEmpById(Integer id);
//修改员工信息
void updateEmp(Emp emp);
}

View File

@@ -61,4 +61,20 @@ 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);
}
}

View File

@@ -27,4 +27,39 @@
#{id}
</foreach>
</delete>
<update id="updateEmp">
update emp
<set>
<if test="username !=null and username != ''">
username = #{username},
</if>
<if test="password !=null and password != ''">
password = #{password},
</if>
<if test="name !=null and name != ''">
name = #{name},
</if>
<if test="gender !=null ">
gender = #{gender},
</if>
<if test="image !=null and image != ''">
image = #{image},
</if>
<if test="job !=null ">
job = #{job},
</if>
<if test="entrydate !=null ">
entrydate = #{entrydate},
</if>
<if test="deptId !=null ">
dept_id = #{deptId},
</if>
<if test="updateTime !=null">
update_time = #{updateTime}
</if>
</set>
where
id = #{id};
</update>
</mapper>