MyBatis傳參數是map的foreach實現方式


聲明一個value為map的map,然后在foreach的時候

collection="key"

controller層:

String district="章貢區";

String [] ids={"1","2","3"};

map.put("district",district);

map.put("idArr",ids);

xml:注意ids一定要和map中的key一致

<select id="queryByDistrictList" resultType="io.renren.modules.mall.entity.SpuGoodsEntity">
        select * from spu_goods spu,shop s 
        where spu.shop_id=s.id and s.town=#{district} and spu.ext1='no' and spu.goods_state=0 and spu.category_id in
        <foreach item="idArr" collection="idArr" open="(" separator="," close=")">
            #{idArr}
        </foreach>        
         <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if> 
    </select>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM