fangyuan
2022-11-21 c435158ed1ff587939314e84347ee6e38e8f25ec
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
32
33
34
35
36
37
38
39
40
<?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.NewsChannelDao">
 
    <resultMap type="com.ycl.entity.NewsChannel" id="NewsChannelMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="code" column="code" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into news_website.news_channel(name, code, create_time)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.name}, #{entity.code}, #{entity.createTime})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into news_website.news_channel(name, code, create_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.code}, #{entity.createTime})
        </foreach>
        on duplicate key update
         name = values(name) , code = values(code) , create_time = values(create_time)
    </insert>
 
    <insert id="insertOneChannel" keyProperty="id" useGeneratedKeys="true">
        insert into news_website.news_channel(name, code, create_time)
        values (#{entity.name}, #{entity.code}, #{entity.createTime})
    </insert>
 
    <select id="selectAllChannel" resultType="com.ycl.entity.NewsChannel">
        select * from news_channel
    </select>
</mapper>