zoukankan      html  css  js  c++  java
  • Java通过Mybatis实现批量插入数据到Oracle中

    <?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.oracle.mapper.AccountInfoMapper"><!--  接口的全类名 -->
        <!-- type:实体类的全类名 -->
        <resultMap id="BaseResultMap" type="com.oracle.entity.AccountInfo">
            <id column="ID" property="id" jdbcType="DECIMAL" />
            <result column="USERNAME" property="userName" jdbcType="VARCHAR" />
            <result column="PASSWORD" property="password" jdbcType="VARCHAR" />
            <result column="GENDER" property="gender" jdbcType="CHAR" />
            <result column="EMAIL" property="email" jdbcType="VARCHAR" />
            <result column="CREATE_DATE" property="createDate" jdbcType="DATE" />
        </resultMap>
        <!-- id 跟接口中的方法名称保持一致 -->
        <select id="queryAllAccountInfo" resultMap="BaseResultMap">
            select ID,
            USERNAME,PASSWORD,
            GENDER, EMAIL, CREATE_DATE from ACCOUNT_INFO
        </select>
        <insert id="batchInsertAccountInfo" parameterType="java.util.List">
            INSERT INTO ACCOUNT_INFO(ID, USERNAME,PASSWORD,GENDER, EMAIL,CREATE_DATE)
            (
            <foreach collection="list" index="" item="accountInfo"
                separator="union all">
                select
                #{accountInfo.id},
                #{accountInfo.userName},
                #{accountInfo.password},
                #{accountInfo.gender},
                #{accountInfo.email},
                #{accountInfo.createDate}
                from dual
            </foreach>
            )
        </insert>
        
        <insert id="batchInsertAccountInfoUseSeq" parameterType="java.util.List">
            <selectKey resultType="long" keyProperty="id" order="BEFORE"> 
                SELECT ACCOUNT_SEQ.NEXTVAL FROM dual
            </selectKey> 
            INSERT INTO ACCOUNT_INFO(ID, USERNAME,PASSWORD,GENDER, EMAIL,CREATE_DATE)
            SELECT ACCOUNT_SEQ.NEXTVAL, m.* FROM(
            <foreach collection="list" index="" item="accountInfo"
                separator="union all">
                select
                #{accountInfo.userName},
                #{accountInfo.password},
                #{accountInfo.gender},
                #{accountInfo.email},
                sysdate
                from dual
            </foreach>
            ) m
        </insert>
        
        <insert id="insertOne" parameterType="com.oracle.entity.AccountInfo">
            <selectKey resultType="long" keyProperty="id" order="BEFORE"> 
                SELECT ACCOUNT_SEQ.NEXTVAL FROM dual
            </selectKey> 
            INSERT INTO ACCOUNT_INFO(ID, USERNAME,PASSWORD,GENDER, EMAIL,CREATE_DATE)
            values(
                #{id},
                #{userName},
                #{password},
                #{gender},
                #{email},
                sysdate
            )
        </insert>
    </mapper>
  • 相关阅读:
    unable to retrieve container logs for docker kubernetes
    Restart container within pod
    Kubernetes1.3:POD生命周期管理
    Options of the DB storage of prometheus
    prometheus重启hang住问题记录
    prometheus交流资源
    nc 从服务器上传下载文件
    负载均衡监控需求
    prometheus消耗内存问题
    10.Docker 镜像使用
  • 原文地址:https://www.cnblogs.com/zhaoyan001/p/9318820.html
Copyright © 2011-2022 走看看