• 【无标题】


     mybatis 批量插入数据,xml文件到底如何写呀 ?这里备注一下

    1. 批量插入数据:batchInsert

    mapper 代码: 

    1. package com.xxxx.mapper;
    2. import org.apache.ibatis.annotations.Param;
    3. import tk.mybatis.mapper.common.Mapper;
    4. import java.util.List;
    5. public interface XXXXRepoMapper extends Mapper {
    6. void batchInsert(@Param("list") List list);
    7. }

    mapper xml

    1. "1.0" encoding="UTF-8"?>
    2. mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    3. <mapper namespace="com.xx.yy.mapper.XXXRepoMapper">
    4. <resultMap id="BaseResultMap" type="com.xx.yy.XXXXRepo">
    5. <id column="ID" jdbcType="INTEGER" property="id" />
    6. <result column="code" jdbcType="VARCHAR" property="code" />
    7. <result column="name" jdbcType="VARCHAR" property="name" />
    8. <result column="parent_code" jdbcType="VARCHAR" property="parentCode" />
    9. <result column="type" jdbcType="TINYINT" property="type" />
    10. <result column="active_flag" jdbcType="TINYINT" property="activeFlag" />
    11. <result column="creator" jdbcType="BIGINT" property="creator" />
    12. <result column="modifier" jdbcType="BIGINT" property="modifier" />
    13. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    14. <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
    15. resultMap>
    16. <sql id="table_name">
    17. t_xxx_repo
    18. sql>
    19. <sql id="Base_Column_List">
    20. id,code,name,parent_code,type,active_flag,creator,modifier,create_time,modify_time
    21. sql>
    22. <insert id="batchInsert" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
    23. insert into <include refid="table_name"/>
    24. (<include refid="Base_Column_List"/>) values
    25. <foreach collection="list" index="index" item="item" separator=",">
    26. (null,#{item.code,jdbcType=VARCHAR},#{item.name,jdbcType=VARCHAR},#{item.parentCode,jdbcType=VARCHAR},#{item.type,jdbcType=TINYINT},1,
    27. #{item.creator,jdbcType=BIGINT},#{item.modifier,jdbcType=BIGINT},now(),now())
    28. foreach>
    29. insert>
    30. mapper>

    2. 批量更新数据:batchUpdate

  • 相关阅读:
    js前端获取农历日期
    简易消息队列实现 Nodejs + Redis =MQ
    1.HTML表格跨行、跨列操作
    CentOS7启动SSH服务报错
    基于工程车辆/物流车辆/消防车辆远程通信的车队管理解决方案
    解决:第一次用python的pip报错
    爆款自媒体带货脚本,大V不外传的流量密码
    Java数字处理类--Math类--随机数
    Fisco Bcos从入门到国一,宝宝版教学
    MySQL数据库二:MySQL索引
  • 原文地址:https://blog.csdn.net/xzb5566/article/details/132896010