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>  

猜你喜欢

转载自blog.csdn.net/qq_42239765/article/details/82900312