mybatis 传入多参数类型包含list和String等的实现方式:
方法一: 把所有参数封装到map
注意:xml中使用参数需要严格匹配map 中put的key
public void deleteBooks(Map<String, Object> map);
map.put("title", "1hdhd");
map.put("templist",list);
<select id="dynamicForeach3Test" resultType="Blog"> select * from t_blog where title like "%"#{title}"%" and id in <foreach collection="ids" index="index" item="item" open="(" separator="," close=")"> #{item.id} </foreach> </select>
方法二: 指定collection名称,这种方法直观些,推荐
注意:利用@param注解时,因为mapper指定了参数名,xml中使用需要严格匹配
public void deleteBooks(@Param("partnerId")long partnerId ,@Param("templist")List<CPPartnerBookSet> list);
xml 部分:方法一,方法二相同
<delete id="deleteBooks"> delete from cp.tbl_cp_partner_books where partner_id = #{partnerId} and book_id in <foreach collection="templist" index="index" item="item" open="(" separator="," close=")"> #{item.bookId} </foreach> </delete>
特别强调,如果传值 list ,那么list 不能为空,简单说就是确保list中有对象