{"id":7874,"date":"2024-11-14T11:56:27","date_gmt":"2024-11-14T03:56:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7874\/"},"modified":"2024-11-14T11:56:27","modified_gmt":"2024-11-14T03:56:27","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mybatis-%e6%95%b0%e6%8d%ae%e5%ba%93%e5%8e%82%e5%95%86%e6%a0%87%e8%af%86%e6%89%a7%e8%a1%8c%e5%8a%a8%e6%80%81-sql%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7874\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Mybatis \u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\u6267\u884c\u52a8\u6001 SQL\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173130860184964.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 Mybatis \u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\u6267\u884c\u52a8\u6001 SQL\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 Mybatis \u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\u6267\u884c\u52a8\u6001 SQL\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4f7f\u7528 mybatis \u7684\u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\u6267\u884c\u52a8\u6001 sql<\/strong><\/p>\n<p>\u5728 mybatis \u4e2d\u9700\u8981\u6839\u636e\u914d\u7f6e\u53d8\u91cf\u503c\u6267\u884c\u4e0d\u540c sql \u8bed\u53e5\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\u529f\u80fd\u3002<\/p>\n<p>\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u793a\u4f8b\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u5168\u5c40\u914d\u7f6e\u7c7b globalvariable\uff0c\u5176\u4e2d\u5305\u542b databasetype \u53d8\u91cf\uff0c\u8be5\u53d8\u91cf\u6307\u793a\u4f7f\u7528\u7684\u6570\u636e\u5e93\u7c7b\u578b\uff08\u4f8b\u5982 1 \u8868\u793a \uff0c2 \u8868\u793a\u8fbe\u68a6\uff09\u3002<\/p>\n<p>\u5728 xml \u6620\u5c04\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 databaseid \u5c5e\u6027\u6765\u6307\u5b9a\u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\uff0c\u5e76\u6839\u636e\u4e0d\u540c\u7684\u6807\u8bc6\u6267\u884c\u4e0d\u540c\u7684 sql \u8bed\u53e5\uff1a<\/p>\n<pre>&lt;select id=\"selectOne\" resultType=\"com.example.type\"&gt;\n    &lt;if test=\"databaseType = 1\"&gt;\n        ... SQL \u8bed\u53e5\u9488\u5bf9 MySQL\n    &lt;\/if&gt;\n    &lt;if test=\"databaseType = 2\"&gt;\n        ... SQL \u8bed\u53e5\u9488\u5bf9\u8fbe\u68a6\n    &lt;\/if&gt;\n&lt;\/select&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5f53\u6267\u884c\u8be5\u67e5\u8be2\u65f6\uff0cmybatis \u4f1a\u6839\u636e globalvariable.databasetype \u7684\u503c\u52a8\u6001\u9009\u62e9\u8981\u6267\u884c\u7684 sql \u8bed\u53e5\uff0c\u4ece\u800c\u5b9e\u73b0 sql \u7684\u52a8\u6001\u6267\u884c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 Mybatis \u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\u6267\u884c\u52a8\u6001 SQL\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>\u4f7f\u7528 mybatis \u7684\u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\u6267\u884c\u52a8\u6001 sql \u5728 mybatis \u4e2d\u9700\u8981\u6839\u636e\u914d\u7f6e\u53d8\u91cf\u503c\u6267\u884c\u4e0d\u540c sql \u8bed\u53e5\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\u529f\u80fd\u3002 \u5bf9\u4e8e\u7ed9\u5b9a\u7684\u793a\u4f8b\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u5168\u5c40\u914d\u7f6e\u7c7b globalvariable\uff0c\u5176\u4e2d\u5305\u542b databasetype \u53d8\u91cf\uff0c\u8be5\u53d8\u91cf\u6307\u793a\u4f7f\u7528\u7684\u6570\u636e\u5e93\u7c7b\u578b\uff08\u4f8b\u5982 1 \u8868\u793a \uff0c2 \u8868\u793a\u8fbe\u68a6\uff09\u3002 \u5728 xml \u6620\u5c04\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 databaseid \u5c5e\u6027\u6765\u6307\u5b9a\u6570\u636e\u5e93\u5382\u5546\u6807\u8bc6\uff0c\u5e76\u6839\u636e\u4e0d\u540c\u7684\u6807\u8bc6\u6267\u884c\u4e0d\u540c\u7684 sql \u8bed\u53e5\uff1a &lt;select id=&#8221;selectOne&#8221; resultType=&#8221;com.example.type&#8221;&gt; &lt;if test=&#8221;databaseType = 1&#8243;&gt; &#8230; SQL \u8bed\u53e5\u9488\u5bf9 MySQL &lt;\/if&gt; &lt;if test=&#8221;databaseType = 2&#8243;&gt; &#8230; SQL \u8bed\u53e5\u9488\u5bf9\u8fbe\u68a6 &lt;\/if&gt; &lt;\/select&gt; \u767b\u5f55\u540e\u590d\u5236 \u5f53\u6267\u884c\u8be5\u67e5\u8be2\u65f6\uff0cmybatis \u4f1a\u6839\u636e globalvariable.databasetype \u7684\u503c\u52a8\u6001\u9009\u62e9\u8981\u6267\u884c\u7684 sql \u8bed\u53e5\uff0c\u4ece\u800c\u5b9e\u73b0 sql \u7684\u52a8\u6001\u6267\u884c\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 [&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-7874","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7874","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=7874"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7874\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}