Mysql向动态表中插入数据

来源:互联网 发布:淘宝网店代运营公司 编辑:程序博客网 时间:2024/05/21 22:28

向动态表中插入数据,其中表名称是动态的,需要通过map集合进行传参。需要插入的数据时通过list封装的实体类,然后把list集合放入到map中作为参数传递。


sql语句的写法:


    <insert  id = "insertData"  parameterType = "hashmap" >


             insert into ${tableName} (tableName为自己需要插入的表的名称)


            (uuid,temp1,temp2)


             values


             <foreach collection="list"  separator=","  index ="index"   item="item">


                       (

 

                         #( item.uuid,jdbcType=VARCHAR),


                        #( item.temp1,jdbcType=VARCHAR),


                        #( item.temp2,jdbcType=VARCHAR)


                        )


             </foreach>


    </insert>