mybatis foreach example

批量插入:

<insert id="insertBillInfos" parameterType="java.util.List">
    insert into sg_sp_work_bill (
        ID, CODE, NAME, CREATE_DATE, CREATE_USER
    )
    values
    <foreach collection="list" item="item" index="index" separator=",">
    (
        #{item.id,jdbcType=DECIMAL},
        #{item.code,jdbcType=VARCHAR},
        #{item.name,jdbcType=VARCHAR},
        NOW(),
        #{item.createUser,jdbcType=DECIMAL}
    )
    </foreach>
</insert>

批量删除:

<delete id="deleteMenus" parameterType="java.util.List">
    delete from t_acl_menu where id in
    <foreach collection="list" item="id" index="index" open="(" separator="," close=")">
        #{id}
    </foreach>
</delete>

猜你喜欢

转载自www.cnblogs.com/xmsx/p/11601153.html