{"id":7857,"date":"2024-11-14T10:15:25","date_gmt":"2024-11-14T02:15:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7857\/"},"modified":"2024-11-14T10:15:25","modified_gmt":"2024-11-14T02:15:25","slug":"%e5%9c%a8-java-%e4%bb%a3%e7%a0%81%e5%92%8c-mysql-where-%e5%ad%90%e5%8f%a5%e4%b8%ad%e8%bf%9b%e8%a1%8c%e8%bf%90%e7%ae%97%e6%93%8d%e4%bd%9c%ef%bc%8c%e5%93%aa%e4%b8%aa%e6%9b%b4%e5%90%88%e9%80%82%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7857\/","title":{"rendered":"\u5728 Java \u4ee3\u7801\u548c MySQL WHERE \u5b50\u53e5\u4e2d\u8fdb\u884c\u8fd0\u7b97\u64cd\u4f5c\uff0c\u54ea\u4e2a\u66f4\u5408\u9002\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173130264421577.jpg\" class=\"aligncenter\" title=\"\u5728 Java \u4ee3\u7801\u548c MySQL WHERE \u5b50\u53e5\u4e2d\u8fdb\u884c\u8fd0\u7b97\u64cd\u4f5c\uff0c\u54ea\u4e2a\u66f4\u5408\u9002\uff1f\u63d2\u56fe\" alt=\"\u5728 Java \u4ee3\u7801\u548c MySQL WHERE \u5b50\u53e5\u4e2d\u8fdb\u884c\u8fd0\u7b97\u64cd\u4f5c\uff0c\u54ea\u4e2a\u66f4\u5408\u9002\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 java \u4ee3\u7801\u548c  where \u5b50\u53e5\u4e2d\u8fdb\u884c\u8fd0\u7b97\u64cd\u4f5c<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u5728\u8fdb\u884c\u6570\u636e\u5e93\u67e5\u8be2\u65f6\uff0c\u5bf9\u5b57\u6bb5\u8fdb\u884c\u8fd0\u7b97\u64cd\u4f5c\uff0c\u7a76\u7adf\u5e94\u8be5\u5728 java \u4ee3\u7801\u4e2d\u5b8c\u6210\u8fd8\u662f\u5728 mysql \u7684 where \u5b50\u53e5\u4e2d\u6267\u884c\uff1f<\/p>\n<p><strong>\u8ba8\u8bba\uff1a<\/strong><\/p>\n<p>\u4e00\u4e2a\u5e38\u89c1\u7684\u573a\u666f\u662f\u9700\u8981\u5bf9\u8868\u4e2d\u7684\u4e00\u4e2a\u5b57\u6bb5\u8fdb\u884c\u52a0\u4e00\u64cd\u4f5c\u3002\u5982\u679c\u8be5\u5b57\u6bb5\u5efa\u7acb\u4e86\u7d22\u5f15\uff0c\u5c06\u64cd\u4f5c\u653e\u5728 where \u5b50\u53e5\u4e2d\u4f3c\u4e4e\u66f4\u6709\u6548\uff0c\u56e0\u4e3a mysql \u53ef\u4ee5\u5229\u7528\u7d22\u5f15\u5feb\u901f\u67e5\u627e\u6570\u636e\u3002\u7136\u800c\uff0c\u8fd9\u6837\u505a\u5b58\u5728\u4e00\u4e9b\u95ee\u9898\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li> <strong>\u7d22\u5f15\u5931\u6548\uff1a<\/strong>where \u5b50\u53e5\u4e2d\u7684\u8868\u8fbe\u5f0f\u64cd\u4f5c\u4f1a\u4f7f\u7d22\u5f15\u5931\u6548\u3002<\/li>\n<li> <strong>\u4ee3\u7801\u6e05\u6670\u5ea6\uff1a<\/strong>sql \u8bed\u53e5\u4e2d\u52a0\u5165\u4e1a\u52a1\u903b\u8f91\u4f1a\u964d\u4f4e\u5176\u53ef\u8bfb\u6027\u548c\u6613\u7ef4\u62a4\u6027\u3002<\/li>\n<li> <strong>\u8bed\u6cd5\u590d\u6742\u5ea6\uff1a<\/strong>\u5728 where \u5b50\u53e5\u4e2d\u8fdb\u884c\u590d\u6742\u8fd0\u7b97\u53ef\u80fd\u9700\u8981\u7e41\u7410\u7684\u8bed\u6cd5\u3002<\/li>\n<\/ul>\n<p><strong>\u5efa\u8bae\uff1a<\/strong><\/p>\n<p>\u8003\u8651\u5230\u4e0a\u8ff0\u95ee\u9898\uff0c\u6211\u5efa\u8bae\u5c06\u8fd0\u7b97\u64cd\u4f5c\u653e\u5728 java \u4ee3\u7801\u4e2d\u6267\u884c\u3002<\/p>\n<p><strong>\u7406\u7531\uff1a<\/strong><\/p>\n<ul>\n<li>java \u4ee3\u7801\u66f4\u6613\u4e8e\u9605\u8bfb\u548c\u7406\u89e3\u3002<\/li>\n<li>java \u53ef\u4ee5\u5728\u8fd0\u7b97\u8fc7\u7a0b\u4e2d\u63d0\u4f9b\u7075\u6d3b\u6027\uff0c\u4f8b\u5982\u6761\u4ef6\u5224\u65ad\u6216\u5faa\u73af\u3002<\/li>\n<li>\u5c06 sql \u8bed\u53e5\u9650\u5236\u4e3a\u6267\u884c\u5355\u7eaf\u7684\u6570\u636e\u5e93\u64cd\u4f5c\uff0c\u6709\u52a9\u4e8e\u4fdd\u6301\u5176\u7b80\u6d01\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 mybatis \u65f6\uff0c\u53ef\u4ee5\u5728 java \u4ee3\u7801\u4e2d\u4f7f\u7528 foreach \u5faa\u73af\u5bf9 age \u5b57\u6bb5\u8fdb\u884c\u52a0\u4e00\u64cd\u4f5c\uff1a<\/p>\n<pre>list&lt;integer&gt; ages = arrays.aslist(1, 2, 3);\nmap&lt;string, object&gt; params = new hashmap&lt;&gt;();\nparams.put(\"ages\", ages);\n\/\/ ...<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\uff0c\u5728 sql \u8bed\u53e5\u4e2d\uff0c\u4f7f\u7528\u53c2\u6570\u5316\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT id, age\nFROM users\nWHERE age IN (#{ages})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u65e2\u53ef\u4ee5\u4fdd\u6301 sql \u8bed\u53e5\u7684\u7b80\u6d01\u6027\uff0c\u53c8\u53ef\u4ee5\u5728 java \u4ee3\u7801\u4e2d\u7075\u6d3b\u5730\u6267\u884c\u8fd0\u7b97\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728 Java \u4ee3\u7801\u548c MySQL WHERE \u5b50\u53e5\u4e2d\u8fdb\u884c\u8fd0\u7b97\u64cd\u4f5c\uff0c\u54ea\u4e2a\u66f4\u5408\u9002\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>\u5728 java \u4ee3\u7801\u548c where \u5b50\u53e5\u4e2d\u8fdb\u884c\u8fd0\u7b97\u64cd\u4f5c \u95ee\u9898\uff1a\u5728\u8fdb\u884c\u6570\u636e\u5e93\u67e5\u8be2\u65f6\uff0c\u5bf9\u5b57\u6bb5\u8fdb\u884c\u8fd0\u7b97\u64cd\u4f5c\uff0c\u7a76\u7adf\u5e94\u8be5\u5728 java \u4ee3\u7801\u4e2d\u5b8c\u6210\u8fd8\u662f\u5728 mysql \u7684 where \u5b50\u53e5\u4e2d\u6267\u884c\uff1f \u8ba8\u8bba\uff1a \u4e00\u4e2a\u5e38\u89c1\u7684\u573a\u666f\u662f\u9700\u8981\u5bf9\u8868\u4e2d\u7684\u4e00\u4e2a\u5b57\u6bb5\u8fdb\u884c\u52a0\u4e00\u64cd\u4f5c\u3002\u5982\u679c\u8be5\u5b57\u6bb5\u5efa\u7acb\u4e86\u7d22\u5f15\uff0c\u5c06\u64cd\u4f5c\u653e\u5728 where \u5b50\u53e5\u4e2d\u4f3c\u4e4e\u66f4\u6709\u6548\uff0c\u56e0\u4e3a mysql \u53ef\u4ee5\u5229\u7528\u7d22\u5f15\u5feb\u901f\u67e5\u627e\u6570\u636e\u3002\u7136\u800c\uff0c\u8fd9\u6837\u505a\u5b58\u5728\u4e00\u4e9b\u95ee\u9898\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u7d22\u5f15\u5931\u6548\uff1awhere \u5b50\u53e5\u4e2d\u7684\u8868\u8fbe\u5f0f\u64cd\u4f5c\u4f1a\u4f7f\u7d22\u5f15\u5931\u6548\u3002 \u4ee3\u7801\u6e05\u6670\u5ea6\uff1asql \u8bed\u53e5\u4e2d\u52a0\u5165\u4e1a\u52a1\u903b\u8f91\u4f1a\u964d\u4f4e\u5176\u53ef\u8bfb\u6027\u548c\u6613\u7ef4\u62a4\u6027\u3002 \u8bed\u6cd5\u590d\u6742\u5ea6\uff1a\u5728 where \u5b50\u53e5\u4e2d\u8fdb\u884c\u590d\u6742\u8fd0\u7b97\u53ef\u80fd\u9700\u8981\u7e41\u7410\u7684\u8bed\u6cd5\u3002 \u5efa\u8bae\uff1a \u8003\u8651\u5230\u4e0a\u8ff0\u95ee\u9898\uff0c\u6211\u5efa\u8bae\u5c06\u8fd0\u7b97\u64cd\u4f5c\u653e\u5728 java \u4ee3\u7801\u4e2d\u6267\u884c\u3002 \u7406\u7531\uff1a java \u4ee3\u7801\u66f4\u6613\u4e8e\u9605\u8bfb\u548c\u7406\u89e3\u3002 java \u53ef\u4ee5\u5728\u8fd0\u7b97\u8fc7\u7a0b\u4e2d\u63d0\u4f9b\u7075\u6d3b\u6027\uff0c\u4f8b\u5982\u6761\u4ef6\u5224\u65ad\u6216\u5faa\u73af\u3002 \u5c06 sql \u8bed\u53e5\u9650\u5236\u4e3a\u6267\u884c\u5355\u7eaf\u7684\u6570\u636e\u5e93\u64cd\u4f5c\uff0c\u6709\u52a9\u4e8e\u4fdd\u6301\u5176\u7b80\u6d01\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002 \u793a\u4f8b\uff1a \u4f7f\u7528 mybatis \u65f6\uff0c\u53ef\u4ee5\u5728 java \u4ee3\u7801\u4e2d\u4f7f\u7528 foreach \u5faa\u73af\u5bf9 age \u5b57\u6bb5\u8fdb\u884c\u52a0\u4e00\u64cd\u4f5c\uff1a list&lt;integer&gt; ages = arrays.aslist(1, 2, 3); map&lt;string, [&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-7857","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7857","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=7857"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7857\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}