MyBatis批量插入List数据实现(MySQL)
1. xml文件
<?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="mapper.ErrorAccountMapper">
<insert id="InsertList" parameterType="java.util.List" useGeneratedKeys="true" >
insert into error_open_account
( id,branchName,branchCode,orgName,orgId,clientId,clientName,account,accountName,openDate,checkDate,closeDate,expireDate,moneyType,subjectId,businessCode,exchangeMark,accountState,accountProperty,safeAccountNature,addTime,folderTime)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.id},
#{item.branchName},
#{item.branchCode},