查询回显:就是根据id查询员工信息
EmpController:
@GetMapping("/emps/{id}")
public Result getById(@PathVariable Integer id){
Emp emp=empService.geyById(id);
return Result.success(emp);
}
EmpService:
@Override
public Emp geyById(Integer id) {
return empMapper.getById(id);
}
EmpMapper:
@Select("select * from emp where id=#{id}")
Emp getById(Integer id);
---------------------------------------
修改员工:
根据id更新
EmpController:
@PutMapping("/emps")
public Result update(@RequestBody Emp emp){//接受JSON格式的数据
empService.update(emp);
return Result.success();
}
EmpService:
@Override
public void update(Emp emp) {
//补充基础信息(修改员工信息时,要多一步对更新时间的修改)
emp.setUpdateTime(LocalDateTime.now());
empMapper.update(emp);
}
EmpMapper:
void update(Emp emp);
EmpMapper.xml:
<update id="update">
update emp
<set>
<if test="username!=null">username=#{username},</if>
<if test="password!=null">password=#{password},</if>
<if test="name!=null">name=#{name},</if>
<if test="gender!=null">gender=#{gender},</if>
<if test="image!=null">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>