当传入list和String时候 或者 传入String[] 类型和String时候
mapper:
int batchDeleteCode(@Param("map")Map<String,Object> map);
Set<String> selectInCode(@Param("map")Map<String,Object> map);
service
list[String]时
public int batchDeleteCode(List<String> codes, String batch) {
Map<String,Object> map=new HashMap<>();
map.put("batch",batch);
map.put("codes",codes);
return pubNumberFamilyTempMapper.batchDeleteCode(map) ;
}
String[]时
public Set<String> selectInCode(String[] codes,String batch) {
Map<String,Object> map=new HashMap<>();
map.put("codes",codes);
map.put("batch",batch);
return pubNumberFamilyTempMapper.selectInCode(map);
}
xml
<delete id="batchDeleteCode" parameterType="java.util.Map">
delete from pubnumber_family_temp where batch =#{map.batch} and code in
<foreach collection="map.codes" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
<select id="selectInCode" resultType="java.lang.String" parameterType="java.util.Map">
select DISTINCT(patent_number) from pubnumber_family_temp where batch =#{map.batch} and code IN
<foreach collection="map.codes" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
–
当传入set时,parameterType=”java.lang.String” 而不是java.lang.Set
当返回数据是List 《String》 时, resultType=”java.lang.String” 而不是java.util.List
–
类似于批量插入时候,是数组对象
<insert id="insertTempBatch" useGeneratedKeys="true" parameterType="java.util.List">
<selectKey resultType="long" keyProperty="id" order="AFTER">
SELECT
last_insert_id()
</selectKey>
insert into pubnumber_family_temp(patent_number, kind, date1, date2, application_number, group_name, code,batch)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.patentNumber},#{item.kind},#{item.date1},#{item.date2},#{item.applicationNumber},#{item.groupName},#{item.code},#{item.batch})
</foreach>
</insert>