首页 /  技术专区  /  Mybatis 宽屏模式 >

Mybatis中update时set和if动态SQL用法

<update id="updateOperApplyExam" parameterType="com.gl.exam.operApplyExam.entity.OperApplyExam">
    update
        sys_oper_applyexam
    <set>
        <if test="theoryScore != null and theoryScore != ''">
            TheoryScore = #{theoryScore},
        </if>
        <if test="tSRepair != null and tSRepair != ''">
            TSRepair = #{tSRepair},
        </if>
        <if test="operScore != null and operScore != ''">
            OperScore = #{operScore},
        </if>
    </set>
    <where>
        AND ApplyId = #{applyId}
    </where>
</update>

使用<set>标签可以去掉最后一个动态sql拼接的,号



头像
0/200
图片验证码