今天要做批量更新的业务,采用mybaits的foreach动态语句,遇到一些问题做下记录。
情况1:
<update id="" parameterType="">
update tb_thread set isDelete=0
where threadId in (
<foreach collection="list" item="item" index="index" open="" close="" separator=",">
#{item.threadId}
</foreach>
)
</update>
情况2:
这种情况一半会报错,解决方式:在数据库配置上添加 &allowMultiQueries=true
例如:jdbc:mysql://192.168.1.109:3306/healthmanage?characterEncoding=utf-8&allowMultiQueries=true
<update id="" parameterType="">
<foreach collection="list" item="item" index="index">
update tb_question_template_seleteitem_detail set selectedName=#{item.selectedName}
where 1=1 and selectedId =#{item.selectedId };
</foreach>
</update>