mybatis 批量更新报错解决方案:
Mapper
void updateByid(@Param("list") List<实体> list);
xml
<update id="updateByid" parameterType="java.util.ArrayList">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update 表名 bri
<set>
<if test="item.stockQty != null">
bri.name= #{item.name,jdbcType=VARCHAR},
</if>
<if test="item.invQty != null">
bri.age= #{item.age,jdbcType=NUMERIC},
</if>
bri.update_time = CURRENT_TIMESTAMP
</set>
where bri.id = #{item.id,jdbcType=VARCHAR}
</foreach>
</update>
需要注意的点:
1. yml中 allowMultiQueries=true
2.druid:wall:multi-statement-allow: true
mysql:
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: 12345
url: jdbc:mysql://localhost:3306/phone_mng?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false&**allowMultiQueries=true**
druid:
wall:
multi-statement-allow: true