MyBatis 動態SQL使用心得之Map中Key判斷

當使用Map做爲參數時,可以用_parameter.containsKey(變量名)來判斷map中是否包含有些變量:

    <select id="selectRule" parameterType="Map" resultType="com.ourangel.weixin.domain.db.Rule">
        SELECT ruleId,msgType,event,respId,reqValue,firstRespId,createDate,yn
        FROM oal_tb_rule
        WHERE yn = 1
        <if test="_parameter.containsKey('msgType')">
            AND msgType = #{msgType,jdbcType=VARCHAR})
        </if>
        <if test="_parameter.containsKey('event')">
            AND event = #{event,jdbcType=VARCHAR})
        </if>
    </select>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章