mybatis的mapper.xml文件中传入一个String参数时,在sql中参数名就是_parameter,如果传入一个list怎么处理呢?
有两种方法
1.
int delCardsByGuids(List<String> guids);
//不管dao层参数时什么,xml文件中collection位置名为list
<delete id="delCardsByGuids" parameterType="java.util.List">
delete from T_MSP_RES_CARD
where guid in
<foreach collection="list" item="cardGuid" open="(" separator="," close=")">
#{cardGuid}
</foreach>
</delete>
2.
int delCardsByGuids(@Param("guids") List<String> guids);
//dao层参数中添加注解@Param值 就是xml文件中参数名如下
<delete id="delCardsByGuids" parameterType="java.util.List">
delete from T_MSP_RES_CARD
where guid in
<foreach collection="guids" item="cardGuid" open="(" separator="," close=")">
#{cardGuid}
</foreach>
</delete>
这两种方法都能用,至于数组同理,第一种方法中list该为array就行