条数据,比单条插入可以节省一半的时间
XML代码:
<insert id=
"insertBatch" parameterType=
"ArrayList">
insert intouser(id,account,password,active,status,name,gender,active_date,expiry_date,type,remark,group_id,disable,exam_number,mobile)
values
<foreach collection=
"list"item=
"obj" index=
"index"separator=
"," >
(#{obj.id},#{obj.account},#{obj.password},#{obj.active},#{obj.status},#{obj.name},#{obj.gender},#{obj.active_date},
#{obj.expiry_date},#{obj.type},#{obj.remark},#{obj.group_id},#{obj.disable},#{obj.exam_number},#{obj.mobile})
</foreach>
</insert>
在java中只需要传递list过来就可以了。
我是这样写的:
private ArrayList<Map<String, String>>userList =
new ArrayList<Map<String,String>>();
Map<String,String>userMap=
new HashMap<String,String>();
userMap.put(
"id", userId);
userMap.put(
"account", arr[
0]);
userMap.put(
"password", pas);
userMap.put(
"active", String.valueOf(
1));
userMap.put(
"status", String.valueOf(
1));
userMap.put(
"name", arr[
1]);
userMap.put(
"gender", String.valueOf(gender));
userMap.put(
"active_date", active_date);
userMap.put(
"expiry_date", expiry_date);
userMap.put(
"type", String.valueOf(
3));
userMap.put(
"remark",
null);
userMap.put(
"group_id", String.valueOf(
1));
userMap.put(
"disable", String.valueOf(
0));
userMap.put(
"Exam_number", arr[
15]);
userMap.put(
"phoneNumber", arr[
14]);
userList.add(userMap);
通过循环将数据加入到list,最后将list传递。
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://www.cnblogs.com/captainbed
Mybatis 3+Mysql 实现批量插入
标签:value array sep password htm led key parameter 人工智能