mybatis批量插入和删除

批量插入以user为例
mapper中

int savePics(@Param("users") String users[]);

dao xml中
selectKey为主键Id自增 users为批量插入数组

        <selectKey resultType="java.lang.Long" order="AFTER" keyProperty="id">
            SELECT LAST_INSERT_ID()
        selectKey>

        <foreach collection="users" item="u" separator=",">
            (#{leaderUserId},#{u},#{leaderGroupId},NULL ,NULL ,NULL)
        foreach>

批量删除以user为例
mapper中

int deleteUser(@Param("ids") String id[]);

dao xml中

        <foreach collection="ids" item="id" separator=",">
                    #{id}
        foreach>

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