因为sql语句拼装后,set语句后面可能会多一个逗号,所以要用set标签 set <!-- public void updateEmp(Employee employee);--> <update id="updateEmp">update tb1_employee<set><if test = "lastName!=null">last_name = #{lastName},</if><if test="email!=null">email = #{email},</if><if test = "gender!=null">gender =#{gender}</if> </set>where id = #{id}</update> trim(set) <!-- public void updateEmp(Employee employee);--> <update id="updateEmp">update tb1_employee<trim prefix="set" suffixOverrides=","><if test = "lastName!=null">last_name = #{lastName},</if><if test="email!=null">email = #{email},</if><if test = "gender!=null">gender =#{gender}</if> </trim>where id = #{id}</update>