一.首先要看你的数据库连接上有没有添加<allowMultiQueries=true>
例如:
jdbc:mysql://127.0.0.1:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
如果不加这个配置,批量更新一直报语法错误。
二.xml文件
<update id="batchUpdateSysDrugPinYin" parameterType="com.doctor.common.model.base.SysDrug">
<foreach collection="sysDrugList" index="index" item="item" separator=";" close=";">
update goods
<set>
pinyin = #{item.pinyin}
</set>
where akid = #{item.goodsId}
</foreach>
</update>
这样批量更新的sql正常运行了。
本文介绍如何正确配置MySQL连接字符串以支持多条语句执行,并提供了一个使用MyBatis进行批量更新的XML配置示例。首先,确保数据库连接中包含allowMultiQueries=true参数。其次,在XML文件中使用foreach标签进行批量更新操作。
423

被折叠的 条评论
为什么被折叠?



