{"id":200639,"date":"2025-05-06T08:25:54","date_gmt":"2025-05-06T00:25:54","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200639\/"},"modified":"2025-05-06T08:25:54","modified_gmt":"2025-05-06T00:25:54","slug":"spring-boot-%e6%9f%a5%e8%af%a2%e4%b8%ba%e7%a9%ba%ef%bc%8c%e5%a6%82%e4%bd%95%e7%94%a8-mybatis-%e8%af%8a%e6%96%ad-%e5%92%8c-%e7%9a%84%e5%8c%ba%e5%88%ab%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200639\/","title":{"rendered":"Spring Boot \u67e5\u8be2\u4e3a\u7a7a\uff0c\u5982\u4f55\u7528 MyBatis \u8bca\u65ad # \u548c $ \u7684\u533a\u522b\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Spring Boot \u67e5\u8be2\u4e3a\u7a7a\uff0c\u5982\u4f55\u7528 MyBatis \u8bca\u65ad # \u548c $ \u7684\u533a\u522b\uff1f<\/h1>\n<p>\u4eca\u5929\u4e3b\u673a\u5b9d\u8d1d\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\uff0c\u5176\u4e2d\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9\u5305\u62ec\u7b49\u7b49\uff0c\u65e0\u8bba\u4f60\u662f\u5c0f\u767d\u8fd8\u662f\u8001\u624b\uff0c\u90fd\u9002\u5408\u770b\u4e00\u770b\u54e6~\u6709\u597d\u7684\u5efa\u8bae\u4e5f\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u82e5\u662f\u770b\u5b8c\u6709\u6240\u6536\u83b7\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u70b9\u8d5e\u652f\u6301\u5440\uff01\u4e00\u8d77\u52a0\u6cb9\u5b66\u4e60~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241110\/1731223667673060731455f.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>Spring Boot SQL \u67e5\u8be2\u65e0\u7ed3\u679c\uff0c\u5982\u4f55\u8bca\u65ad\uff1f<\/strong><\/p>\n<p>\u5728 Spring Boot \u4e2d\uff0c\u4f60\u9047\u5230\u4e86\u67e5\u8be2\u4e3a\u7a7a\u7684\u95ee\u9898\u3002\u901a\u8fc7\u4e0e Navicat \u4e2d\u7684\u539f\u751f SQL \u67e5\u8be2\u5bf9\u6bd4\uff0c\u53d1\u73b0\u53ea\u6709\u5728 where \u5b50\u53e5\u4e2d\u4f20\u9012\u7a7a\u503c\u65f6\uff0c\u67e5\u8be2\u624d\u6210\u529f\u3002<\/p>\n<p>\u6839\u636e\u95ee\u9898\u7684\u63cf\u8ff0\uff0c\u6211\u4eec\u6765\u5206\u6790\u6f5c\u5728\u7684\u539f\u56e0\uff1a<\/p>\n<p><strong># \u548c $ \u7684\u533a\u522b<\/strong><\/p>\n<p>\u5728 MyBatis \u4e2d\uff0c#{} \u548c ${} \u7528\u4e8e\u8868\u793a\u67e5\u8be2\u53c2\u6570\u3002#{}\u7528\u4e8e\u8bbe\u7f6e\u76f4\u63a5\u503c\uff0c\u800c${}\u7528\u4e8e\u8bbe\u7f6e\u52a8\u6001\u503c\u3002<\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u4f7f\u7528 #{} \u4f20\u9012\u7a7a\u503c\uff0c\u5219 SQL \u8bed\u53e5\u5c06\u65e0\u6cd5\u8bc6\u522b\u4f5c\u4e3a\u6761\u4ef6\uff0c\u56e0\u6b64\u5bfc\u81f4\u67e5\u8be2\u4e3a\u7a7a\u3002\u800c\u4f7f\u7528 ${} \u52a8\u6001\u4f20\u9012\u7a7a\u503c\u65f6\uff0cSQL \u8bed\u53e5\u53ef\u4ee5\u5c06\u6761\u4ef6\u66ff\u6362\u4e3a NULL\uff0c\u4ece\u800c\u8fd4\u56de\u9884\u671f\u7ed3\u679c\u3002<\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u8bf7\u5c1d\u8bd5\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>\u786e\u4fdd where \u5b50\u53e5\u4e2d\u7684\u53d8\u91cf\u5df2\u6b63\u786e\u521d\u59cb\u5316\uff0c\u660e\u786e\u4f20\u9012\u975e\u7a7a\u503c\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u4f7f\u7528\u7a7a\u503c\u8fdb\u884c\u67e5\u8be2\uff0c\u8bf7\u4f7f\u7528 ${} \u8bed\u6cd5\u8bbe\u7f6e\u52a8\u6001\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u63a8\u8350\u5de5\u5177<\/strong><\/p>\n<p>\u82e5\u8981\u65b9\u4fbf\u5730\u8c03\u8bd5\u6b64\u7c7b\u95ee\u9898\uff0c\u5efa\u8bae\u5b89\u88c5 MyBatis Log \u63d2\u4ef6\u3002\u8be5\u63d2\u4ef6\u5c06\u5728\u63a7\u5236\u53f0\u4e2d\u6253\u5370\u8be6\u7ec6\u7684 SQL \u8bed\u53e5\u548c\u53c2\u6570\uff0c\u5e2e\u52a9\u4f60\u5feb\u901f\u627e\u51fa\u95ee\u9898\u6240\u5728\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aSpring Boot \u67e5\u8be2\u4e3a\u7a7a\uff0c\u5982\u4f55\u7528 MyBatis \u8bca\u65ad # \u548c $ \u7684\u533a\u522b\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Spring Boot \u67e5\u8be2\u4e3a\u7a7a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200639","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200639"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200639\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}