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>

猜你喜欢

转载自www.cnblogs.com/SmallStrange/p/12982379.html
今日推荐