美文网首页
mybatis 动态语法

mybatis 动态语法

作者: anyoneofus_4aa9 | 来源:发表于2023-07-17 15:24 被阅读0次
    //更新
    <update id="updateJob" parameterType="SysJob">
            update sys_job
            <set>
                <if test="jobName != null and jobName != ''">job_name = #{jobName},</if>
                <if test="jobGroup != null and jobGroup != ''">job_group = #{jobGroup},</if>
                <if test="invokeTarget != null and invokeTarget != ''">invoke_target = #{invokeTarget},</if>
                <if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if>
                <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy = #{misfirePolicy},</if>
                <if test="concurrent != null and concurrent != ''">concurrent = #{concurrent},</if>
                <if test="status !=null">status = #{status},</if>
                <if test="remark != null and remark != ''">remark = #{remark},</if>
                <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
                update_time = now()
            </set>
            where job_id = #{jobId}
        </update>
    
    //新增
    <insert id="insertJob" parameterType="SysJob" useGeneratedKeys="true" keyProperty="jobId">
            insert into sys_job(
                <if test="jobId != null and jobId != 0">job_id,</if>
                <if test="jobName != null and jobName != ''">job_name,</if>
                <if test="jobGroup != null and jobGroup != ''">job_group,</if>
                <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if>
                <if test="cronExpression != null and cronExpression != ''">cron_expression,</if>
                <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy,</if>
                <if test="concurrent != null and concurrent != ''">concurrent,</if>
                <if test="status != null and status != ''">status,</if>
                <if test="remark != null and remark != ''">remark,</if>
                <if test="createBy != null and createBy != ''">create_by,</if>
                create_time
            )values(
                <if test="jobId != null and jobId != 0">#{jobId},</if>
                <if test="jobName != null and jobName != ''">#{jobName},</if>
                <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if>
                <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if>
                <if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if>
                <if test="misfirePolicy != null and misfirePolicy != ''">#{misfirePolicy},</if>
                <if test="concurrent != null and concurrent != ''">#{concurrent},</if>
                <if test="status != null and status != ''">#{status},</if>
                <if test="remark != null and remark != ''">#{remark},</if>
                <if test="createBy != null and createBy != ''">#{createBy},</if>
                now()
            )
        </insert>
    
            //批量删除
     <delete id="deleteJobByIds" parameterType="Long">
        delete from sys_job where job_id in
        <foreach collection="array" item="jobId" open="(" separator="," close=")">
            #{jobId}
           </foreach>
     </delete>
    
         //批量更新
        <update id="updateDeptChildren" parameterType="java.util.List">
            update sys_dept set ancestors =
            <foreach collection="depts" item="item" index="index"
                separator=" " open="case dept_id" close="end">
                when #{item.deptId} then #{item.ancestors}
            </foreach>
            where dept_id in
            <foreach collection="depts" item="item" index="index"
                separator="," open="(" close=")">
                #{item.deptId}
            </foreach>
        </update>
    
        <update id="deletePersonIds">
            update bus_key_person set del_flag = '1'
            WHERE person_id IN
            <foreach item="id" collection="array" open="(" separator="," close=")">
                #{id}
            </foreach>
        </update>
    
    

    相关文章

      网友评论

          本文标题:mybatis 动态语法

          本文链接:https://www.haomeiwen.com/subject/kkegudtx.html