1.List类型插入:java
<insert id="batchInsertClientDeviceList" parameterType="java.util.List" > INSERT INTO t_client_device_list (order_no,mac_id,client_code,status,order_time) <foreach collection="list" item="item" index="index" separator="union all"> select #{item.orderNo, jdbcType=VARCHAR},#{item.macId, jdbcType=VARCHAR} from dual </foreach> </insert>
1.1List类型查询:bash
<select id="getClientDeviceList" parameterType="java.util.List" resultType="Device"> select * from t_devices where id in <foreach collection="list" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> </select>
2.参数array类型查询:code
<select id="getClientDeviceList" parameterType="java.util.ArrayList" resultType="Device"> select * from t_devices where id in <foreach collection="array" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> </select>
3.参数Map类型查询:get
map中存放了一个元素key为ids,value为List<String>用于id in的条件it
<select id="getClientDeviceList" parameterType="java.util.HashMap" resultType="Device"> select * from t_devices where mac like "%"#{mac}"%" and id in <foreach collection="ids" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> </select>