1. 程式人生 > >MyBatis動態SQL使用,傳入引數Map中的Key判斷

MyBatis動態SQL使用,傳入引數Map中的Key判斷

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

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