mybatis批量插入方式
作者:互联网
mybatis批量操作
1)更新的方式:
-- 批量更新
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
UPDATE BS_MENU
<trim prefix="SET" suffixOverrides=",">
<if test="item.menuName != null and item.menuName !=''">
MENU_NAME = #{item.menuName},
</if>
<if test="item.updateTime != null">
UPDATE_TIME = #{item.updateTime},
</if>
</trim>
WHERE MENU_ID = #{item.menuId,jdbcType=VARCHAR}
</foreach>
UPDATE BS_MENU <set> <if test="status != null"> STATUS = #{status,jdbcType=DECIMAL}, </if> </set> where MENU_NAME IN <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach>
2)批量新增
<insert id="saveBatch" parameterType="list"> insert INTO BS_MENU (MENU_ID,MENU_NAME, UPDATE_TIME) <foreach collection="list" item="item" index="index" separator="union all"> select #{item.menuId}, #{item.menuName}, to_date(#{item.updateTime}, 'yyyy-mm-dd hh24:mi:ss') from dual </foreach> </insert>
标签:NAME,批量,MENU,插入方式,UPDATE,item,BS,mybatis 来源: https://www.cnblogs.com/blogslee/p/16548942.html