{"id":200358,"date":"2025-05-06T12:33:51","date_gmt":"2025-05-06T04:33:51","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200358\/"},"modified":"2025-05-06T12:33:51","modified_gmt":"2025-05-06T04:33:51","slug":"%e5%9c%a8-spring-boot-%e4%b8%ad%e4%bd%bf%e7%94%a8-mybatis%ef%bc%8c%e5%a6%82%e4%bd%95%e7%81%b5%e6%b4%bb%e9%80%89%e6%8b%a9%e5%8a%a8%e6%80%81-sql-%e5%8f%82%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200358\/","title":{"rendered":"\u5728 Spring Boot \u4e2d\u4f7f\u7528 MyBatis\uff0c\u5982\u4f55\u7075\u6d3b\u9009\u62e9\u52a8\u6001 SQL \u53c2\u6570\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5728 Spring Boot \u4e2d\u4f7f\u7528 MyBatis\uff0c\u5982\u4f55\u7075\u6d3b\u9009\u62e9\u52a8\u6001 SQL \u53c2\u6570\uff1f<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u4e3b\u8981\u8bb2\u89e3\u4e86\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u4e3b\u673a\u5b9d\u8d1d\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241102\/17305542346726297a4d1ac.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5728 spring boot \u4f7f\u7528 mybatis \u4e2d\u7684\u52a8\u6001 sql \u53c2\u6570\u9009\u62e9<\/strong><\/p>\n<p>\u5728 spring boot \u4e2d\u4f7f\u7528 mybatis \u65f6\uff0c\u5f53\u9700\u8981\u4ece\u6570\u636e\u5e93\u4e2d\u67e5\u8be2\u7279\u5b9a\u7c7b\u578b\u7684\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\u6765\u6307\u5b9a\u6761\u4ef6\uff1a<\/p>\n<p><strong>\u5c06\u6761\u4ef6\u5199\u6b7b\u5728 sql \u8bed\u53e5\u4e2d<\/strong><\/p>\n<p>\u5982\u679c\u8981\u67e5\u8be2\u7684\u7c7b\u578b\u660e\u786e\uff0c\u5982\u4ec5\u67e5\u8be2 type=cat \u7684\u6570\u636e\uff0c\u53ef\u4ee5\u76f4\u63a5\u5c06\u8be5\u6761\u4ef6\u5199\u6b7b\u5728 sql \u8bed\u53e5\u4e2d\uff0c\u5373 select * from animal where type=&#8221;cat&#8221;;\u3002\u8fd9\u79cd\u65b9\u5f0f\u7b80\u5355\u4fbf\u6377\uff0c\u4f46\u7f3a\u4e4f\u7075\u6d3b\u6027\u3002\u5982\u679c\u4ee5\u540e\u9700\u8981\u67e5\u8be2\u5176\u4ed6\u7c7b\u578b\u7684\u52a8\u7269\uff0c\u5219\u9700\u8981\u4fee\u6539 sql \u8bed\u53e5\u3002<\/p>\n<p><strong>\u5728 service \u0e2b\u0e23\u0e37\u0e2d controller \u4e2d\u4f20\u9012\u53c2\u6570<\/strong><\/p>\n<p>\u53e6\u4e00\u79cd\u7b56\u7565\u662f\u5c06\u67e5\u8be2\u6761\u4ef6\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9 mybatis \u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3a querycatfromanimal \u7684\u65b9\u6cd5\uff0c\u5e76\u63a5\u53d7\u4e00\u4e2a type \u53c2\u6570\u3002\u5728\u8c03\u7528\u6b64\u65b9\u6cd5\u65f6\uff0c\u5c06 cat \u503c\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\u5373\u53ef\u3002\u6b64\u65b9\u6cd5\u7684\u597d\u5904\u662f\u5177\u6709\u826f\u597d\u7684\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u6539\u53d8\u53c2\u6570\u503c\u6765\u67e5\u8be2\u4e0d\u540c\u7684\u7c7b\u578b\u6570\u636e\u3002<\/p>\n<p><strong>\u53c2\u6570\u679a\u4e3e\u4f18\u5316<\/strong><\/p>\n<p>\u4e3a\u4e86\u8fdb\u4e00\u6b65\u63d0\u9ad8\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u679a\u4e3e\u6765\u5b9a\u4e49\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u5982 animaltype.cat\u3001animaltype.dog \u7b49\u3002\u5728 service \u5c42\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6839\u636e\u7c7b\u578b\u679a\u4e3e\u83b7\u53d6\u6570\u636e\u7684\u65b9\u6cd5\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>List&lt;Animal&gt; getAnimalsByType(AnimalType type) { ... }<\/pre>\n<p>\u5728 controller \u4e2d\uff0c\u53ea\u9700\u8c03\u7528\u6b64\u65b9\u6cd5\u5e76\u4f20\u5165\u76f8\u5e94\u7684\u679a\u4e3e\u503c\u5373\u53ef\u3002<\/p>\n<p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u5728 spring boot \u4e2d\u4f7f\u7528 mybatis \u65f6\uff0c\u9009\u62e9\u52a8\u6001 sql \u53c2\u6570\u7684\u7b56\u7565\u53d6\u51b3\u4e8e\u67e5\u8be2\u9700\u6c42\u7684\u7075\u6d3b\u6027\u3002\u5982\u679c\u67e5\u8be2\u6761\u4ef6\u660e\u786e\u4e14\u65e0\u9700\u4fee\u6539\uff0c\u5219\u76f4\u63a5\u5199\u6b7b\u5728 sql \u8bed\u53e5\u4e2d\u5373\u53ef\u3002\u5982\u679c\u9700\u8981\u66f4\u7075\u6d3b\u7684\u67e5\u8be2\u65b9\u5f0f\uff0c\u5219\u5efa\u8bae\u5728 service \u6216 controller \u4e2d\u4f20\u9012\u53c2\u6570\uff0c\u6216\u4f7f\u7528\u53c2\u6570\u679a\u4e3e\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u5728 Spring Boot \u4e2d\u4f7f\u7528 MyBatis\uff0c\u5982\u4f55\u7075\u6d3b\u9009\u62e9\u52a8\u6001 SQL \u53c2\u6570\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Spring Boot \u4e2d\u4f7f&#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-200358","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200358","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=200358"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200358\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}