{"id":25499,"date":"2024-11-24T15:48:20","date_gmt":"2024-11-24T07:48:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25499\/"},"modified":"2024-11-24T15:48:20","modified_gmt":"2024-11-24T07:48:20","slug":"mybatis%e5%8a%a8%e6%80%81sql%e4%bc%98%e5%8c%96%ef%bc%9a%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e6%8b%bc%e6%8e%a5%e9%94%99%e8%af%af%e5%af%bc%e8%87%b4%e6%9f%a5%e8%af%a2%e6%8a%a5%e9%94%99%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25499\/","title":{"rendered":"Mybatis\u52a8\u6001SQL\u4f18\u5316\uff1a\u5982\u4f55\u907f\u514d\u62fc\u63a5\u9519\u8bef\u5bfc\u81f4\u67e5\u8be2\u62a5\u9519\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173062340616873.jpg\" class=\"aligncenter\" title=\"Mybatis\u52a8\u6001SQL\u4f18\u5316\uff1a\u5982\u4f55\u907f\u514d\u62fc\u63a5\u9519\u8bef\u5bfc\u81f4\u67e5\u8be2\u62a5\u9519\uff1f\u63d2\u56fe\" alt=\"Mybatis\u52a8\u6001SQL\u4f18\u5316\uff1a\u5982\u4f55\u907f\u514d\u62fc\u63a5\u9519\u8bef\u5bfc\u81f4\u67e5\u8be2\u62a5\u9519\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>mybatis\u52a8\u6001\u62a5\u9519<\/strong><\/p>\n<p>\u5728mybatis\u4e2d\u8fdb\u884c\u52a8\u6001sql\u67e5\u8be2\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230sql\u62fc\u63a5\u4e0d\u5f53\uff0c\u5bfc\u81f4\u67e5\u8be2\u62a5\u9519\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5178\u578b\u7684\u62a5\u9519\uff1a<\/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>\u9488\u5bf9\u8be5\u95ee\u9898\uff0c\u6709\u51e0\u79cd\u5e38\u89c1\u7684\u4f18\u5316\u65b9\u6cd5\uff1a<\/p>\n<p>\u65b9\u6cd51\uff1a\u4f7f\u7528 \u6807\u7b7e <\/p>\n<pre>&lt;pre class=\"brush:php;toolbar:false\"&gt;&lt;code&gt;&lt;if test=\"type == 'idcard'\"&gt;a.id_card = #{code}&lt;\/if&gt;\n&lt;if test=\"type == 'unitcode'\"&gt;a.unit_code = #{code}&lt;\/if&gt;&lt;\/code&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u65b9\u6cd52\uff1a\u4f7f\u7528 \u6807\u7b7e <\/p>\n<pre>&lt;pre class=\"brush:php;toolbar:false\"&gt;&lt;code&gt;&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;&lt;\/code&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f18\u5316\u540e\u7684sql\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>\u91c7\u7528\u4e0a\u8ff0\u65b9\u6cd5\u53ef\u4ee5\u6709\u6548\u89e3\u51b3mybatis\u52a8\u6001sql\u67e5\u8be2\u4e2d\u51fa\u73b0\u7684sql\u62fc\u63a5\u9519\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMybatis\u52a8\u6001SQL\u4f18\u5316\uff1a\u5982\u4f55\u907f\u514d\u62fc\u63a5\u9519\u8bef\u5bfc\u81f4\u67e5\u8be2\u62a5\u9519\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\u6001\u62a5\u9519 \u5728mybatis\u4e2d\u8fdb\u884c\u52a8\u6001sql\u67e5\u8be2\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230sql\u62fc\u63a5\u4e0d\u5f53\uff0c\u5bfc\u81f4\u67e5\u8be2\u62a5\u9519\u7684\u60c5\u51b5\u3002 \u4e0b\u9762\u662f\u4e00\u4e2a\u5178\u578b\u7684\u62a5\u9519\uff1a 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 \u9488\u5bf9\u8be5\u95ee\u9898\uff0c\u6709\u51e0\u79cd\u5e38\u89c1\u7684\u4f18\u5316\u65b9\u6cd5\uff1a \u65b9\u6cd51\uff1a\u4f7f\u7528 \u6807\u7b7e &lt;pre class=&#8221;brush:php;toolbar:false&#8221;&gt;&lt;code&gt;&lt;if test=&#8221;type == &#8216;idcard'&#8221;&gt;a.id_card = #{code}&lt;\/if&gt; &lt;if test=&#8221;type == &#8216;unitcode'&#8221;&gt;a.unit_code = #{code}&lt;\/if&gt;&lt;\/code&gt; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd52\uff1a\u4f7f\u7528 \u6807\u7b7e &lt;pre class=&#8221;brush:php;toolbar:false&#8221;&gt;&lt;code&gt;&lt;choose&gt; &lt;when test=&#8221;type == idcard&#8221;&gt; and a.id_card = #{code} &lt;\/when&gt; [&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-25499","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25499","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=25499"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25499\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}