1.根据员工id查询信息
 
Controller层
    /*
    * 根据员工id查询信息
    * */
    @GetMapping("/{id}")
    @ApiOperation("根据员工id查询信息")
    public Result<Employee> getById(@PathVariable Integer id){
        log.info("根据员工id查询信息{}",id);
        Employee employee=employeeService.getById(id);
        return Result.success(employee);
    }Service层和Serviceimpl层
    /*
     * 根据员工id查询信息
     * */
    Employee getById(Integer id);    /*
     * 根据员工id查询信息
     * */
    @Override
    public Employee getById(Integer id) {
       Employee employee=employeeMapper.select(id);
       employee.setPassword("******");
        return employee;
    }mapper层
    /*
     * 根据员工id查询信息
     * */
    @Select("select * from employee where id=#{id}")
    Employee select(Integer id);2.编辑员工信息
Controller层
    /*
    * 编辑员工信息
    * */
    @PutMapping
    @ApiOperation("编辑员工信息")
    public Result edit(@RequestBody EmployeeDTO employeeDTO){
        log.info("编辑员工信息{}",employeeDTO);
        employeeService.edit(employeeDTO);
        return Result.success();
    }service和serviceimpl层
    /*
    * 编辑员工信息
    * */
    void edit(EmployeeDTO employeeDTO);    /*
    * 编辑员工信息
    * */
    @Override
    public void edit(EmployeeDTO employeeDTO) {
        Employee employee=new Employee();
        //对象的属性拷贝
        BeanUtils.copyProperties(employeeDTO,employee);
        employee.setUpdateTime(LocalDateTime.now());
        employee.setUpdateUser(BaseContext.getCurrentId());
        employeeMapper.update(employee);
    }这里使用了对象的属性拷贝,调用BeanUtils的copyProperties方法将employeeDTO的属性传给了
employee。
每一次更新或修改数据都要记得更新setUpdateTime,setUpdateUser
mapper层
由于实现update功能的sql语句比较复杂所以这里使用动态sql的方式去实现,在xml配置文件里配置动态的sql。
    void update(Employee employee);    <!--更新员工信息-->
    <!--前面是employee的属性-->
    <update id="update" parameterType="Employee">
        update employee
        <set>
            <if test="name != null"> name = #{name},</if>
            <if test="username != null"> username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="phone != null"> phone = #{phone}, </if>
            <if test="sex != null"> sex = #{sex},</if>
            <if test="idNumber != null"> id_number = #{idNumber},</if>
            <if test="updateTime != null">update_Time = #{updateTime},</if>
            <if test="updateUser != null">update_User = #{updateUser},</if>
            <if test="status != null">status = #{status},</if>
        </set>
        where id=#{id}
    </update>注意:set标签里不能写注释
test里填的是判断条件,前面的判断属性判断的都是是employee的属性




















