第一种方式html
<update id="updateBatch" parameterType="Map"> update aa set a=#{fptm}, b=#{csoftrain} where c in <foreach collection="cs" index="index" item="item" pen="("separator=","close=")"> #{item} </foreach> </update>
第二种方式java
修改数据库链接配置:&allowMultiQueries=truemysql
好比:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=truesql
<update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update test <set> test=${item.test}+1 </set> where id = ${item.id} </foreach> </update>这种方式,能够一次执行多条SQL语句