MyBatis动态SQL使用,传入参数Map中的Key判断

<select id="" parameterType="Map"   resultMap="commodityResultMap" >
        SELECT c.id c_id,c.variety_id,c.nickName c_nickName,c.description c_description,c.ordinaryPrice c_ordinaryPrice,c.memberPrice c_memberPrice,c.path c_path,v.id v_id,v.nickName v_nickName 
        FROM commodity c 
        INNER JOIN variety v 
        ON c.variety_id=v.id 
        where 1=1  
        
             <!-- _parameter.containsKey('键') 作用:判断键是否存在返回值boolean  #{键}取对应的值   !必须三处键值对应,否则取不到值-->
             <if test="_parameter.containsKey('varietyID')"> 
                and v.id=#{varietyID}
             </if>
    </select>

  • 此做法的好处,可做多条件查询。

 

posted on 2016-09-13 20:22  艺意  阅读(2634)  评论(0编辑  收藏  举报