{"id":6697,"date":"2024-11-14T10:06:24","date_gmt":"2024-11-14T02:06:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6697\/"},"modified":"2024-11-14T10:06:24","modified_gmt":"2024-11-14T02:06:24","slug":"jdbctemplate-batchupdate-%e5%a6%82%e4%bd%95%e8%ae%b0%e5%bd%95%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\/6697\/","title":{"rendered":"JdbcTemplate.batchUpdate \u5982\u4f55\u8bb0\u5f55\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\/172973815989852.jpg\" class=\"aligncenter\" title=\"JdbcTemplate.batchUpdate \u5982\u4f55\u8bb0\u5f55\u4e0d\u5339\u914d Where \u5b50\u53e5\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" alt=\"JdbcTemplate.batchUpdate \u5982\u4f55\u8bb0\u5f55\u4e0d\u5339\u914d Where \u5b50\u53e5\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u8bb0\u5f55 jdbctemplate.batchupdate \u4e2d\u4e0d\u5339\u914d where \u5b50\u53e5\u7684\u8bb0\u5f55<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 jdbctemplate.batchupdate \u6279\u91cf\u6267\u884c sql \u8bed\u53e5\u65f6\uff0c\u5f53\u67d0\u4e9b\u8bb0\u5f55\u4e0e where \u5b50\u53e5\u4e0d\u5339\u914d\u65f6\uff0c\u9700\u8981\u4e00\u79cd\u65b9\u6cd5\u6765\u8bb0\u5f55\u8fd9\u4e9b\u672a\u66f4\u65b0\u7684\u8bb0\u5f55\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 jdbctemplate.batchupdate \u8fd4\u56de\u7684 int[] \u6570\u7ec4\u3002\u8be5\u6570\u7ec4\u5305\u542b\u6bcf\u4e2a sql \u8bed\u53e5\u6267\u884c\u540e\u66f4\u65b0\u7684\u8bb0\u5f55\u6570\u91cf\u3002\u5982\u679c\u6570\u7ec4\u4e2d\u7684\u503c\u4e3a 0\uff0c\u5219\u8868\u793a\u8be5\u8bed\u53e5\u6ca1\u6709\u5339\u914d\u4efb\u4f55\u8bb0\u5f55\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u8be5 int[] \u6570\u7ec4\u6765\u8bb0\u5f55\u4e0d\u5339\u914d\u7684\u8bb0\u5f55\uff1a<\/p>\n<pre>String sql = \"update set i=? where orderId=?\";\nList&lt;Object[]&gt; valueList = [ [1, 1], [2, 2], [3, 3] ];\n\nint[] updateCounts = jdbcTemplate.batchUpdate(sql, valueList);\nfor (int i = 0; i &lt; updateCounts.length; i++) {\n    if (updateCounts[i] == 0) {\n        \/\/ \u8bb0\u5f55\u4e0d\u5339\u914d\u7684\u8bb0\u5f55\n        \/\/ \u4f8b\u5982\uff0c\u8bb0\u5f55 valueList[i]\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u8bc6\u522b\u51fa\u54ea\u4e9b\u8bb0\u5f55\u6ca1\u6709\u88ab\u66f4\u65b0\u5230\u6570\u636e\u5e93\u4e2d\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJdbcTemplate.batchUpdate \u5982\u4f55\u8bb0\u5f55\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>\u8bb0\u5f55 jdbctemplate.batchupdate \u4e2d\u4e0d\u5339\u914d where \u5b50\u53e5\u7684\u8bb0\u5f55 \u5728\u4f7f\u7528 jdbctemplate.batchupdate \u6279\u91cf\u6267\u884c sql \u8bed\u53e5\u65f6\uff0c\u5f53\u67d0\u4e9b\u8bb0\u5f55\u4e0e where \u5b50\u53e5\u4e0d\u5339\u914d\u65f6\uff0c\u9700\u8981\u4e00\u79cd\u65b9\u6cd5\u6765\u8bb0\u5f55\u8fd9\u4e9b\u672a\u66f4\u65b0\u7684\u8bb0\u5f55\u3002 \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 jdbctemplate.batchupdate \u8fd4\u56de\u7684 int[] \u6570\u7ec4\u3002\u8be5\u6570\u7ec4\u5305\u542b\u6bcf\u4e2a sql \u8bed\u53e5\u6267\u884c\u540e\u66f4\u65b0\u7684\u8bb0\u5f55\u6570\u91cf\u3002\u5982\u679c\u6570\u7ec4\u4e2d\u7684\u503c\u4e3a 0\uff0c\u5219\u8868\u793a\u8be5\u8bed\u53e5\u6ca1\u6709\u5339\u914d\u4efb\u4f55\u8bb0\u5f55\u3002 \u4e0b\u9762\u7684\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u8be5 int[] \u6570\u7ec4\u6765\u8bb0\u5f55\u4e0d\u5339\u914d\u7684\u8bb0\u5f55\uff1a String sql = &#8220;update set i=? where orderId=?&#8221;; List&lt;Object[]&gt; valueList = [ [1, 1], [2, 2], [3, 3] ]; int[] updateCounts = jdbcTemplate.batchUpdate(sql, valueList); for (int i = 0; i &lt; updateCounts.length; [&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-6697","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6697","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=6697"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6697\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}