mybatis使用foreach进行批量删除插入

插入:

mapper:

Integer insertBatchUser(List<User> userList);

xml:

<insert id="insertBatchUser" parameterType="java.util.List">
        INSERT INTO User(USER_ID, VER)
        values
        <foreach collection="list" item="entity" index="index" separator=",">
            (#{entity.userId},#{entity.ver}
        </foreach>
</insert>

删除:

mapper:

Integer deleteBatchUser(List<User> userList);

xml:

<delete id="deleteBatchUser" parameterType="java.util.List">
    DELETE FROM USER
    WHERE USER_ID IN
    <foreach item="item" collection="list" separator="," open="(" close=")" index="">
        #{item.userId}
    </foreach>
</delete>

你可能感兴趣的:(mybatis-plus,mybatis)