mybatis的怎么在mysql中循 环更新数据

mybatis的怎么在mysql中循 环更新数据,第1张

Java mysql mybatis批量更新数据库,采用以下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true

例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true

<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 Server),可以采用以下方式

<insert id="xxx" parameterType="yyy" useGeneratedKeys="true" keyProperty="id">.... </insert>

对于不支持自动生成主键(如Oracle),可以采用以下方式:

<insert id="xxx" parameterType="yyy"><selectKey keyProperty="id" resultType="long" order="BEFORE">select my_seq.nextval from dual </selectKey>.... </insert>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6661174.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存