mybatis的批量插入

<?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.jjmc.dcl.dao.SaveMessageLogsDao">
<insert id="insertMessageLogs"  parameterType="java.util.List">
insert into DCL_Message_His (Mobile,User_Type,Message_Type,Send_Status,Created_Data,Des) 
values
<foreach collection="list" item="SaveMessageLogs" index="index" separator="," >  
(#{SaveMessageLogs.mobile},
#{SaveMessageLogs.userType},
#{SaveMessageLogs.messageType},
#{SaveMessageLogs.sendStatus},
#{SaveMessageLogs.createDate},
#{SaveMessageLogs.des})
</foreach>
</insert>
</mapper>
传入的参数类型是一个list<SaveMessageLogs>,SaveMessageLogs是自己定义的一个model类。
================================================================================
<?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.jjmc.dcl.dao.SaveMessageLogsDao">
<insert id="insertBatchMessageLogs"  parameterType="java.util.List">
insert into DCL_Message_His (Mobile,User_Type,Message_Type,Send_Status,Created_Data,Des) 
values
<foreach collection="list" item="item" index="index" separator="," >  
(#{item.mobile},
#{item.userType},
#{item.messageType},
#{item.sendStatus},
#{item.createDate},
#{item.des})
</foreach>
</insert> 
传入的参数也可以是List<Map<Object,Object>>,这样就不需要新建一个model类。

posted @ 2017-10-29 20:52  me-ht  阅读(155)  评论(0编辑  收藏  举报