因为oracle与mysql语句的执行差别,使用mybatis批量插入/更新操作时mapper文件的配置方法不尽相同, oracle库的配置文件和mysql库的配置文件写法如下,备用。
<?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.whg.test.userBean">
<resultMap type="userBean" id="userMap">
<id property="USER_ID" column="USER_ID" />
<result property="USER_NAME" column="USER_NAME" />
<result property="USER_CODE" column="USER_CODE" />
<result property="INS_TIME" column="INS_TIME" />
</resultMap>
<!-- 批量插入 oracle的配置文件写法-->
<insert id="addUserByBatch" parameterType="java.util.List">
insert into USER_TEST (
USER_ID,
USER_NAME,
USER_CODE,
INS_TIME)
(
<foreach collection="list" item="item" index="index" separator="UNION ALL">
select
#{item.USER_ID,jdbcType=VARCHAR},
#{item.USER_NAME,jdbcType=VARCHAR},
#{item.USER_CODE,jdbcType=VARCHAR},
SYSDATE
from dual
</foreach>
)
</insert>
<!-- 批量插入 MYSQL 数据库的配置文件写法-->
<insert id="addfkxxByBatch" parameterType="java.util.List">
insert into USER_TEST (
USER_ID,
USER_NAME,
USER_CODE,
INS_TIME)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.USER_ID,jdbcType=VARCHAR},
#{item.USER_NAME,jdbcType=VARCHAR},
#{item.USER_CODE,jdbcType=VARCHAR}
SYSDATE
)
</foreach>
</insert>
</mapper>