mybatis中使用foreach构造多like查询及批量插入

来源:互联网 发布:网络安全技术身份认证 编辑:程序博客网 时间:2024/06/09 22:04

使用foreach批量查询:

<!--wc根据商品分类名字,查询检测能力模糊得到数据 --><select id="likeGoodsType" resultMap="goodstypeMap">SELECT <include refid="proAll"/> FROM  goods_type WHERE 1>2 OR <foreach collection="array" item="item" index="index"  separator="OR">              `NAME` LIKE CONCAT('%',#{item},'%')         </foreach></select>
使用foreach批量插入:
<!--店铺入驻时,插入多条待检项目 --><insert id="saves">insert into store_detectability(id,store_id,test_name,test_price,parent_id,goods_type_id)values<foreach collection="list" item="item" index="index" separator="," >     (#{item.id},#{item.storeId},#{item.testName},#{item.testPrice},#{item.parentId},#{item.goodsTypeId}) </foreach> </insert>

ps:使用单个list或者array传参时无需指定parameterType
详细参数请参考:http://blog.csdn.net/bareheadzzq/article/details/8006131
使用foreach批量插入

1 0