原文:https://blog.csdn.net/jason5186/article/details/40896043
<select id="countByUserList" resultType="_int" parameterType="list">
select count(*) from users
<where>
id in
<foreach item="item" collection="list" separator="," open="(" close=")" index="">
#{item.id, jdbcType=NUMERIC}
</foreach>
</where>
</select>
::select count(*) from users WHERE id in ( ? , ? )
<insert id="addList">
INSERT INTO DELIVER
(
<include refid="selectAllColumnsSql"/>
)
<foreach collection="deliverList" item="item" separator="UNION ALL">
SELECT
#{item.id, jdbcType=NUMERIC},
#{item.name, jdbcType=VARCHAR}
FROM DUAL
</foreach>
</insert>
::insert into deliver select ?,? from dual union all select ?,? from dual
<insert id="ins_string_string">
insert into string_string (key, value) values
<foreach item="item" index="key" collection="map"
open="" separator="," close="">(#{key}, #{item})</foreach>
</insert>
::
insert into string_string (key, value) values (?, ?) , (?, ?)
-- mysql
<select id="sel_key_cols" resultType="int">
select count(*) from key_cols where
<foreach item="item" index="key" collection="map"
open="" separator="AND" close="">${key} = #{item}</foreach>
</select>
::
select count(*) from key_cols where col_a = ? AND col_b = ? (一定要注意到$和#的区别,$的参数直接输出,#的参数会被替换为?,然后传入参数值执行。)