这个跟mybatis 无关,只跟你最终的sql有关,mybatis update 可以添加if 条件判断的

mybatis 动态sql

<!-- 4 if/set(判断参数) - 将实体类不为空的属性更新 -->  
<update id="updateStudent_if_set" parameterType="liming.student.manager.data.model.StudentEntity">  
    UPDATE STUDENT_TBL  
        <if test="studentName != null and studentName != '' ">  
            STUDENT_TBL.STUDENT_NAME = #{studentName},  
        <if test="studentSex != null and studentSex != '' ">  
            STUDENT_TBL.STUDENT_SEX = #{studentSex},  
        <if test="studentBirthday != null ">  
            STUDENT_TBL.STUDENT_BIRTHDAY = #{studentBirthday},  
        <if test="studentPhoto != null ">  
            STUDENT_TBL.STUDENT_PHOTO = #{studentPhoto, javaType=byte[], jdbcType=BLOB, typeHandler=org.apache.ibatis.type.BlobTypeHandler},  
        <if test="classId != '' ">  
            STUDENT_TBL.CLASS_ID = #{classId}  
        <if test="placeId != '' ">  
            STUDENT_TBL.PLACE_ID = #{placeId}  
    WHERE STUDENT_TBL.STUDENT_ID = #{studentId};      
</update>  
评论 ( 1 )