您好,登錄后才能下訂單哦!
批量刪除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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。