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.lwp.study.dao.StudentMapper">
    <insert id="addDpzsAll">
        insert all
        <foreach collection="list" item="on">
            into gylyyzx_dpzs_all
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="on.scount!=null and on.scount!='' ">
                    scount,
                </if>
                <if test="on.state!=null and on.state!='' ">
                    state,
                </if>
                <if test="on.redcount!=null and on.redcount!='' ">
                    redcount,
                </if>
                <if test="on.yelcount!=null and on.yelcount!='' ">
                    yelcount,
                </if>
                <if test="on.bluecount!=null and on.bluecount!='' ">
                    bluecount,
                </if>
                <if test="on.city!=null and on.city!='' ">
                    city,
                </if>
                <if test="on.year!=null and on.year!='' ">
                    year,
                </if>
                <if test="on.ywcf!=null and on.ywcf!='' ">
                    ywcf,
                </if>
                <if test="on.ywbm!=null and on.ywbm!='' ">
                    ywbm,
                </if>
                <if test="on.interfaceType!=null and on.interfaceType!='' ">
                    interfaceType,
                </if>
            </trim>
            values
            <trim prefix="(" suffix=")" suffixOverrides="," >
                <if test="on.scount!=null and on.scount!='' ">
                    #{on.scount},
                </if>
                <if test="on.state!=null and on.state!='' ">
                    #{on.state},
                </if>
                <if test="on.redcount!=null and on.redcount!='' ">
                    #{on.redcount},
                </if>
                <if test="on.yelcount!=null and on.yelcount!='' ">
                    #{on.yelcount},
                </if>
                <if test="on.bluecount!=null and on.bluecount!='' ">
                    #{on.bluecount},
                </if>
                <if test="on.city!=null and on.city!='' ">
                    #{on.city},
                </if>
                <if test="on.year!=null and on.year!='' ">
                    #{on.year},
                </if>
                <if test="on.ywcf!=null and on.ywcf!='' ">
                    #{on.ywcf},
                </if>
                <if test="on.ywbm!=null and on.ywbm!='' ">
                    #{on.ywbm},
                </if>
                <if test="on.interfaceType!=null and on.interfaceType!='' ">
                    #{on.interfaceType},
                </if>
            </trim>
        </foreach>
        select * from dual
    </insert>
</mapper>
posted @ 2021-07-11 13:17  幸运刘  阅读(213)  评论(0)    收藏  举报