批量删除mybatis多参数效率的实例分析,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
最近遇到批量删除表数据的问题并且是根据多个参数,我这个情况是有一个参数比较特殊是一样的值,但是我还是把它作为通用情况。做了实验测试。
代码测试如下:
Map param =new HashMap(); param.put("userId",userId); List<String> listJobIds = sysUserJobdel.stream().map(SysUserJob::getJobId).distinct().collect(Collectors.toList()); param.put("jobIds",listJobIds);for (int i = 0; i < 10000; i++) { SysUserJob userJob =new SysUserJob(); userJob.setJobId(String.valueOf(SystemUtils.nextId())); userJob.setUserId(userId); sysUserJobdel.add(userJob); listJobIds.add(String.valueOf(SystemUtils.nextId())); } param.put("jobIds",listJobIds);long begintime1 = System.currentTimeMillis();sysUserMapper.deleteUserJobs(param);long endtime1 = System.currentTimeMillis();long costTime1 = ( endtime1 - begintime1 ); System.err.println( "costTime1===="+ costTime1);long begintime2 = System.currentTimeMillis();sysUserMapper.deleteUserJob(sysUserJobdel);long endtime2 = System.currentTimeMillis();long costTime2 = ( endtime2 - begintime2 ); System.err.println( "costTime2===="+ costTime2);long begintime3 = System.currentTimeMillis();sysUserMapper.deletesUsersJobs(sysUserJobdel);long endtime3 = System.currentTimeMillis();long costTime3 = ( endtime3 - begintime3 ); System.err.println( "costTime3===="+ costTime3);
<delete id="deleteUserJobs" parameterType="java.util.Map">delete from sys_user_job where user_id = #{userId} and job_id in<foreach collection="jobIds" index="index" item="item" open="(" separator="," close=")">#{item}</foreach></delete><delete id="deleteUserJob" parameterType="java.util.List">delete from sys_user_job where<foreach collection="list" item="item" separator=" or " index="index">(user_id = #{item.userId} and job_id= #{item.jobId})</foreach></delete><delete id="deletesUsersJobs" parameterType="java.util.List">delete from sys_user_job where (user_id,job_id) in<foreach collection="list" item="item" index="index" separator="," open="(" close=")">(#{item.userId},#{item.jobId})</foreach></delete>
三次结果输出:
costTime1====173
costTime2====1673
costTime3====414
costTime1====115
costTime2====1523
costTime3====391
costTime1====105
costTime2====1501
costTime3====417
看完上述内容,你们掌握批量删除mybatis多参数效率的实例分析的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。