{"id":25440,"date":"2024-11-24T09:28:25","date_gmt":"2024-11-24T01:28:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25440\/"},"modified":"2024-11-24T09:28:25","modified_gmt":"2024-11-24T01:28:25","slug":"mybatis-%e5%8a%a8%e6%80%81-sql-%e6%9f%a5%e8%af%a2%e4%b8%ad%ef%bc%8c%e5%a6%82%e4%bd%95%e4%bc%98%e5%8c%96%e5%8c%85%e5%90%ab%e5%a4%9a%e4%b8%aa%e6%9d%a1%e4%bb%b6%e4%b8%94%e4%bd%bf%e7%94%a8-or-%e8%bf%9e-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25440\/","title":{"rendered":"Mybatis \u52a8\u6001 SQL \u67e5\u8be2\u4e2d\uff0c\u5982\u4f55\u4f18\u5316\u5305\u542b\u591a\u4e2a\u6761\u4ef6\u4e14\u4f7f\u7528 or \u8fde\u63a5\u7684\u67e5\u8be2\u8bed\u53e5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173061274733740.jpg\" class=\"aligncenter\" title=\"Mybatis \u52a8\u6001 SQL \u67e5\u8be2\u4e2d\uff0c\u5982\u4f55\u4f18\u5316\u5305\u542b\u591a\u4e2a\u6761\u4ef6\u4e14\u4f7f\u7528 or \u8fde\u63a5\u7684\u67e5\u8be2\u8bed\u53e5\uff1f\u63d2\u56fe\" alt=\"Mybatis \u52a8\u6001 SQL \u67e5\u8be2\u4e2d\uff0c\u5982\u4f55\u4f18\u5316\u5305\u542b\u591a\u4e2a\u6761\u4ef6\u4e14\u4f7f\u7528 or \u8fde\u63a5\u7684\u67e5\u8be2\u8bed\u53e5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>mybatis\u52a8\u6001sql\u67e5\u8be2\u4f18\u5316<\/strong><\/p>\n<p>\u5728\u4f7f\u7528mybatis\u52a8\u6001sql\u65f6\uff0c\u5982\u4f55\u4f18\u5316\u4ee5\u4e0b\u67e5\u8be2\uff1f<\/p>\n<pre>select * from table a where a.project_id=#{projectid} and a.id != #{id} and a.status=3 and a.id_card = #{code} or a.unit_code = #{code}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>\u4f18\u5316\u540e\u7684\u67e5\u8be2\u8bed\u53e5\u5982\u4e0b\uff1a<\/p>\n<pre>select * from table a \n&lt;where&gt;\n a.project_id=#{projectId}\n and a.id != #{id}\n and a.status=3 \n&lt;choose&gt;\n    &lt;when test=\"type == idCard\"&gt; \n        and a.id_card = #{code}\n    &lt;\/when&gt;\n&lt;when test=\"type == unitCode\"&gt;and a.unit_code = #{code}&lt;\/when&gt;\n    &lt;otherwise&gt;  \n    &lt;\/otherwise&gt;  \n&lt;\/choose&gt;\n&lt;\/where&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u539f\u67e5\u8be2\u8bed\u53e5\u4e2d\u4f7f\u7528 or \u6761\u4ef6\u8fde\u63a5\u4e24\u4e2a if \u6761\u4ef6\uff0c\u4f1a\u5bfc\u81f4\u62fc\u63a5\u5230 sql \u65f6\u7684\u8bed\u6cd5\u9519\u8bef\u3002\u4f18\u5316\u540e\u7684\u67e5\u8be2\u8bed\u53e5\u4f7f\u7528 choose when otherwise \u8bed\u6cd5\u7ed3\u6784\uff0c\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u6d4b\u8bd5\u6761\u4ef6\u52a8\u6001\u9009\u62e9\u62fc\u63a5\u7684 sql \u7247\u6bb5\uff0c\u907f\u514d\u4e86\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMybatis \u52a8\u6001 SQL \u67e5\u8be2\u4e2d\uff0c\u5982\u4f55\u4f18\u5316\u5305\u542b\u591a\u4e2a\u6761\u4ef6\u4e14\u4f7f\u7528 or \u8fde\u63a5\u7684\u67e5\u8be2\u8bed\u53e5\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mybatis\u52a8\u6001sql\u67e5\u8be2\u4f18\u5316 \u5728\u4f7f\u7528mybatis\u52a8\u6001sql\u65f6\uff0c\u5982\u4f55\u4f18\u5316\u4ee5\u4e0b\u67e5\u8be2\uff1f select * from table a where a.project_id=#{projectid} and a.id != #{id} and a.status=3 and a.id_card = #{code} or a.unit_code = #{code} \u767b\u5f55\u540e\u590d\u5236 \u89e3\u7b54\uff1a \u4f18\u5316\u540e\u7684\u67e5\u8be2\u8bed\u53e5\u5982\u4e0b\uff1a select * from table a &lt;where&gt; a.project_id=#{projectId} and a.id != #{id} and a.status=3 &lt;choose&gt; &lt;when test=&#8221;type == idCard&#8221;&gt; and a.id_card = #{code} &lt;\/when&gt; &lt;when test=&#8221;type == unitCode&#8221;&gt;and a.unit_code = [&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-25440","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25440","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=25440"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25440\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}