使用mybatis进行批量更新的时候,在mapper.xml中的写法如下:
<update id="updateUserNeteaseAccount">
<foreach collection="userList" separator=";" item="user">
update ti_addrbook_user_company
set accid = #{user.accid},
token = #{user.token}
where user_id = #{user.userId}
and company_id = #{user.companyId}
</foreach>
</update>
添加完发现在程序中运行的时候,会提示添加错误,查了一下资料,发现了问题。当批量更新的时候,需要在数据库连接的后面加上
&allowMultiQueries=true,这样才能执行多余的sql。