MyBatis中的一些批量操作语句

1、批量插入语句

<insert id="batchInsertMjOrganizationCategoryList" parameterType="java.util.List">
    INSERT INTO mj_organization_category (
    `organization_id`,`category_id`
    ) VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.organizationId},#{item.categoryId}
            )
        </foreach>
    ;
</insert>
2、批量获取语句
<select id="batchGetMjUserOrganizationListByBpmCodeAndOrgInfo"
        resultType="com.sankuai.meituan.donation.modules.manage.domain.vo.InstitutionAuditVO">
    select bpm_code, id AS org_id, org_name, org_code, founding_time, org_mail, charge_user
    from mj_user_organization
    where 1=1
    <if test="list != null and list.size() != 0">
        and bpm_code in
        <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
    </if>
    <if test="orgCode != null and orgCode != ''">
        AND org_code LIKE CONCAT('%',#{orgCode},'%')
    </if>
    <if test="orgName != null and orgName != ''">
        AND org_name LIKE CONCAT('%',#{orgName},'%')
    </if>
    ;
</select>
3、批量删除语句
<delete id="batchDeleteStation" parameterType="java.util.Map">
    DELETE FROM station WHERE station_floor_id=#{stationFloorId} AND station_num IN
    <foreach collection="set" item="item" open="(" separator="," close=")">
        #{item}
    </foreach>
</delete>
4、批量更新语句
同上



猜你喜欢

转载自blog.csdn.net/timchen525/article/details/80315090