1. 程式人生 > >mybatis傳入list集合批量刪除

mybatis傳入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)