tlias管理系统-员工管理查询回显&修改员工信息功能实现
This commit is contained in:
@@ -52,4 +52,25 @@ public class EmpController {
|
|||||||
empService.save(emp);
|
empService.save(emp);
|
||||||
return Result.success();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,4 +34,10 @@ public interface EmpMapper {
|
|||||||
@Insert("insert into emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
|
@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})")
|
"values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
|
||||||
void save(Emp emp);
|
void save(Emp emp);
|
||||||
|
|
||||||
|
//根据id查询员工
|
||||||
|
@Select("select * from emp where id = #{id}")
|
||||||
|
Emp getEmpById(Integer id);
|
||||||
|
|
||||||
|
void updateEmp(Emp emp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,10 @@ public interface EmpService {
|
|||||||
|
|
||||||
//新增员工
|
//新增员工
|
||||||
void save(Emp emp);
|
void save(Emp emp);
|
||||||
|
|
||||||
|
//根据id查询员工
|
||||||
|
Emp getEmpById(Integer id);
|
||||||
|
|
||||||
|
//修改员工信息
|
||||||
|
void updateEmp(Emp emp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,4 +61,20 @@ public class EmpServiceImpl implements EmpService {
|
|||||||
emp.setUpdateTime(LocalDateTime.now());
|
emp.setUpdateTime(LocalDateTime.now());
|
||||||
empMapper.save(emp);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,39 @@
|
|||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</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>
|
</mapper>
|
||||||
Reference in New Issue
Block a user