mybatis传入list集合批量删除

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33229669/article/details/85015926

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)

猜你喜欢

转载自blog.csdn.net/qq_33229669/article/details/85015926