MyBatis批量插入模板
Posted JAGNIG
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MyBatis批量插入模板相关的知识,希望对你有一定的参考价值。
oracle:
<insert id="insertBatch" parameterType="List"> INSERT INTO TStudent(name,age) <foreach collection="list" item="item" index="index" open="("close=")"separator="union all"> SELECT #{item.name} as a, #{item.age} as b FROM DUAL </foreach> </insert>
<insert id ="insertCodeBatch" parameterType="java.util.List" > <selectKey resultType ="java.lang.Integer" keyProperty= "id" order= "AFTER"> SELECT LAST_INSERT_ID() </selectKey > insert into redeem_code (bach_id, code, type, facevalue,create_user,create_time) values <foreach collection ="list" item="reddemCode" index= "index" separator =","> ( #{reddemCode.batchId}, #{reddemCode.code}, #{reddemCode.type}, #{reddemCode.facevalue}, #{reddemCode.createUser}, #{reddemCode.createTime} ) </foreach > </insert >
以上是关于MyBatis批量插入模板的主要内容,如果未能解决你的问题,请参考以下文章