MyBatie使用List数据类型进行批量删除
[原文链接]https://blog.csdn.net/txd2016_5_11/article/details/83215504
进行一项批量删除的功能,使用MyBatis进行,数据类型为List,下面上代码:
<!-- public int deleteList(List<Integer> list); -->
<delete id="deleteList" parameterType="java.util.List">
DELETE FROM t_g_vaddedtax WHERE addedId in(
<foreach collection="list" item="id" index="index" separator=",">
${id}
</foreach>
);
</delete>
原文链接https://blog.csdn.net/qq_33229669/article/details/85015926
MyBatie使用List对象进行批量删除
Model
public class FastDFSModel {
private String pathId;
private String modelId;
private String csvpath;
private String resultpath;
private String updatetime;
}
Dao
void deleteDateById(List<FastDFSModel> deleteList);
mapper
其中parameterType写为list
foreach 中的collection写为"list"
item 为遍历的每一项,代表着model
在变量中用#{item.pathId}来获取值
此业务为通过id进行删除
其中open="(" separator="," close=")"为拼接的in查询,把id用逗号拼接起来
<delete id="deleteDateById" parameterType="java.util.List">
delete from T_FASTDFS_PATH t where t.path_id in
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item.pathId,jdbcType=VARCHAR}
</foreach>
</delete>
控制台打印如下
delete from T_FASTDFS_PATH t where t.path_id in ( ? , ? , ? )
PreparedStatement - ==> Parameters: 2(String), 1(String), 3(String)