mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.panzhihua.service_community.dao.McsProductLabelDAO">
 
    <resultMap type="com.panzhihua.service_community.entity.McsProductLabel" id="McsProductLabelMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="productId" column="product_id" jdbcType="INTEGER"/>
        <result property="labelId" column="label_id" jdbcType="INTEGER"/>
        <result property="labelName" column="label_name" jdbcType="VARCHAR"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.mcs_product_label(product_id, label_id, label_name)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.productId}, #{entity.labelId}, #{entity.labelName})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.mcs_product_label(product_id, label_id, label_name)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.productId}, #{entity.labelId}, #{entity.labelName})
        </foreach>
        on duplicate key update
        product_id = values(product_id) , label_id = values(label_id) , label_name = values(label_name)
    </insert>
 
</mapper>