fangyuan
2022-11-18 c9d9a680d60722048fec46019b4a7ca36f821c58
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
<?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.ycl.mapper.NewsDepartmentDao">
 
    <resultMap type="com.ycl.entity.NewsDepartment" id="NewsDepartmentMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="deptname" column="deptname" jdbcType="VARCHAR"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into news_website.news_department(deptname)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.deptname})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into news_website.news_department(deptname)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.deptname})
        </foreach>
        on duplicate key update
         deptname = values(deptname)     </insert>
 
</mapper>