zoukankan      html  css  js  c++  java
  • myBatis mySql 批量插入

    <insert id="batchInsert" useGeneratedKeys="true" keyProperty="id" parameterType="java.util.List" >
    INSERT INTO `oauth_client_method`
    (appkey,method)
    VALUES
    <foreach collection="list" item="item" index="index" separator="," >
    (#{item.appkey},#{item.method})
    </foreach>
    </insert>

    ---------------------------------------------------------------------------------------------------------------------------------------------------

    mybatis ,mysql

    插入的时候,主键需要特殊处理

    主键 且  自增长

    上面的代码

    useGeneratedKeys="true" keyProperty="id"

    在单条插入时OK,但是批量插入时应该去掉,否则会报错,因为只能找到list找不到id

    正确如下:

    <insert id="saveBatch" parameterType="java.util.List">
    INSERT INTO cerins_calendar_manager
    (user_id,user_name,phase,grade,subject,publisherVer,ctime,utime)
    VALUES
    <foreach collection="list" item="item" index="index" separator=",">
    (#{item.user_id},#{item.user_name},
    #{item.phase},#{item.grade},#{item.subject},#{item.publisherVer},
    now(),now())
    </foreach>
    </insert>

  • 相关阅读:
    python爬取北京政府信件信息03
    Python3.7 lxml引入etree
    python爬取北京政府信件信息02
    python爬取北京政府信件信息01
    2020.12.2收获
    2020.12.1收获
    2020.11.30收获
    2020.11.29收获
    2020.11.28收获
    2020.11.27收获
  • 原文地址:https://www.cnblogs.com/whoknows1/p/9418116.html
Copyright © 2011-2022 走看看