mybatis常用SQL

moonjerx
2021-10-21 / 0 评论 / 128 阅读 / 正在检测是否收录...
1.SET
<update id="updateStatus">
    UPDATE t_user
    <set>
        <if test="status != null and status != ''">
            status =#{status},
        </if>
        <if test="runStatus != null and runStatus != ''">
            run_status =#{runStatus},
        </if>
    </set>
    WHERE id=#{id}
</update>
2.DELETE/删除指定条数
<delete id="deleteByRobotTeamId">
    DELETE
    from t_user
    WHERE id = #{id}
    <if test="num != null">
        LIMIT #{num}
    </if>
</delete>
3.choose-when结构/IFNULL/MAX/
<update id="save" parameterType="Object">
    INSERT INTO t_robot_chat_expand (chat_word_id,sort, content )
    VALUES(
    #{chatWordId},
    <choose>
        <when test="sort == null">
            (SELECT
            IFNULL(MAX( RCE.sort ) + 1,0)
            FROM
            t_robot_chat_expand RCE
            WHERE
            RCE.chat_word_id = #{chatWordId} ),
        </when>
        <otherwise>
            IF((SELECT
            MAX( RCE.sort )
            FROM
            t_robot_chat_expand RCE
            WHERE
            RCE.chat_word_id = 1 ) &lt; #{sort}, (SELECT
            MAX( RCE.sort ) + 1
            FROM
            t_robot_chat_expand RCE
            WHERE
            RCE.chat_word_id = #{chatWordId} ), #{sort}),
        </otherwise>
    </choose>
    #{content})
</update>
0

评论 (0)

取消

您的IP: