{"id":6721,"date":"2024-11-14T11:41:44","date_gmt":"2024-11-14T03:41:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6721\/"},"modified":"2024-11-14T11:41:44","modified_gmt":"2024-11-14T03:41:44","slug":"%e5%a6%82%e4%bd%95%e6%8d%95%e6%8d%89-jdbctemplate-batchupdate-%e4%b8%ad%e4%b8%8d%e5%8c%b9%e9%85%8d-where-%e5%ad%90%e5%8f%a5%e7%9a%84%e8%ae%b0%e5%bd%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6721\/","title":{"rendered":"\u5982\u4f55\u6355\u6349 jdbcTemplate.batchUpdate \u4e2d\u4e0d\u5339\u914d where \u5b50\u53e5\u7684\u8bb0\u5f55\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172982161378358.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u6355\u6349 jdbcTemplate.batchUpdate \u4e2d\u4e0d\u5339\u914d where \u5b50\u53e5\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u6355\u6349 jdbcTemplate.batchUpdate \u4e2d\u4e0d\u5339\u914d where \u5b50\u53e5\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>jdbctemplate.batchupdate \u5982\u4f55\u6355\u6349\u4e0d\u5339\u914d where \u5b50\u53e5\u7684\u8bb0\u5f55<\/h2>\n<p>\u5728\u4f7f\u7528 jdbctemplate.batchupdate \u8fdb\u884c\u6279\u91cf\u66f4\u65b0\u65f6\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u60c5\u51b5\uff1awhere \u5b50\u53e5\u4e0d\u5339\u914d\uff0c\u5bfc\u81f4\u67d0\u4e9b\u8bb0\u5f55\u65e0\u6cd5\u66f4\u65b0\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u6355\u6349\u548c\u8bb0\u5f55\u8fd9\u4e9b\u4e0d\u5339\u914d\u7684\u8bb0\u5f55\uff1a<\/p>\n<pre>List&lt;Object[]&gt; valueList = new ArrayList&lt;&gt;(); \/\/ \u60a8\u7684\u66f4\u65b0\u503c\u5217\u8868\n\nint[] updatedRows = jdbcTemplate.batchUpdate(sql, valueList, batchSize); \/\/ \u6279\u91cf\u66f4\u65b0\n\nfor (int i = 0; i &lt; updatedRows.length; i++) {\n  if (updatedRows[i] == 0) {\n    \/\/ \u8bb0\u5f55\u4e0d\u5339\u914d\u7684\u8bb0\u5f55\n    Object[] unmatchedRecord = valueList.get(i);\n    System.out.println(\"\u4e0d\u5339\u914d\u7684\u8bb0\u5f55\uff1a\" + Arrays.toString(unmatchedRecord));\n  }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>batchupdate \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a int[] \u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u8868\u793a\u5bf9\u5e94 sql \u8bed\u53e5\u66f4\u65b0\u7684\u8bb0\u5f55\u6570\u91cf\u3002\u5982\u679c\u67d0\u4e2a\u8bb0\u5f55\u4e0d\u5339\u914d where \u5b50\u53e5\uff0c\u5176\u5bf9\u5e94\u7684\u66f4\u65b0\u8bb0\u5f55\u6570\u5c06\u4e3a 0\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u6b64\u4fe1\u606f\u8f7b\u677e\u786e\u5b9a\u672a\u66f4\u65b0\u7684\u8bb0\u5f55\u5e76\u5c06\u5176\u8bb0\u5f55\u4e0b\u6765\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u6355\u6349 jdbcTemplate.batchUpdate \u4e2d\u4e0d\u5339\u914d where \u5b50\u53e5\u7684\u8bb0\u5f55\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>jdbctemplate.batchupdate \u5982\u4f55\u6355\u6349\u4e0d\u5339\u914d where \u5b50\u53e5\u7684\u8bb0\u5f55 \u5728\u4f7f\u7528 jdbctemplate.batchupdate \u8fdb\u884c\u6279\u91cf\u66f4\u65b0\u65f6\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u60c5\u51b5\uff1awhere \u5b50\u53e5\u4e0d\u5339\u914d\uff0c\u5bfc\u81f4\u67d0\u4e9b\u8bb0\u5f55\u65e0\u6cd5\u66f4\u65b0\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u6355\u6349\u548c\u8bb0\u5f55\u8fd9\u4e9b\u4e0d\u5339\u914d\u7684\u8bb0\u5f55\uff1a List&lt;Object[]&gt; valueList = new ArrayList&lt;&gt;(); \/\/ \u60a8\u7684\u66f4\u65b0\u503c\u5217\u8868 int[] updatedRows = jdbcTemplate.batchUpdate(sql, valueList, batchSize); \/\/ \u6279\u91cf\u66f4\u65b0 for (int i = 0; i &lt; updatedRows.length; i++) { if (updatedRows[i] == 0) { \/\/ \u8bb0\u5f55\u4e0d\u5339\u914d\u7684\u8bb0\u5f55 Object[] unmatchedRecord = valueList.get(i); System.out.println(&#8220;\u4e0d\u5339\u914d\u7684\u8bb0\u5f55\uff1a&#8221; + Arrays.toString(unmatchedRecord)); } } \u767b\u5f55\u540e\u590d\u5236 batchupdate \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a int[] \u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u8868\u793a\u5bf9\u5e94 sql [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6721","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6721"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6721\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}