<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update total_score set score=#{item.score}
where user_id =(select id from sys_admin where uk_account=#{item.username})
and time=#{item.time}
</foreach>
像这样执行要40多秒,怎么能快一些呢?
你参照这个写法试试
复制代码
<update id="batchUpdate" parameterType="list">
update songs
<trim prefix="set" suffixOverrides=",">
<trim prefix="path =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.songid!=null">
when songid=#{i.songid} then #{i.path}
</if>
</foreach>
</trim>
</trim>
where songid in
<foreach collection="list" item="i" index="index" open="(" separator="," close=")">
#{i.songid}
</foreach>
</update>
把id加个索引子查询就会快一些
速度慢在了 更具username查询id的那个语句上了。一般来说,你有了用户名,就有id了。如果不再查一次的话,就会快一些。