{"id":25375,"date":"2024-11-24T08:01:42","date_gmt":"2024-11-24T00:01:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25375\/"},"modified":"2024-11-24T08:01:42","modified_gmt":"2024-11-24T00:01:42","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25375\/","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><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173060245346818.jpg\" class=\"aligncenter\" title=\"\u5728 Spring Boot \u4e2d\u4f7f\u7528 MyBatis\uff0c\u5982\u4f55\u7075\u6d3b\u9009\u62e9\u52a8\u6001 SQL \u53c2\u6570\uff1f\u63d2\u56fe\" alt=\"\u5728 Spring Boot \u4e2d\u4f7f\u7528 MyBatis\uff0c\u5982\u4f55\u7075\u6d3b\u9009\u62e9\u52a8\u6001 SQL \u53c2\u6570\uff1f\u63d2\u56fe\" \/><\/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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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\u5728 Spring Boot \u4e2d\u4f7f\u7528 MyBatis\uff0c\u5982\u4f55\u7075\u6d3b\u9009\u62e9\u52a8\u6001 SQL \u53c2\u6570\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>\u5728 spring boot \u4f7f\u7528 mybatis \u4e2d\u7684\u52a8\u6001 sql \u53c2\u6570\u9009\u62e9 \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 \u5c06\u6761\u4ef6\u5199\u6b7b\u5728 sql \u8bed\u53e5\u4e2d \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 \u5728 service \u0e2b\u0e23\u0e37\u0e2d controller \u4e2d\u4f20\u9012\u53c2\u6570 \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 \u53c2\u6570\u679a\u4e3e\u4f18\u5316 \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 List&lt;Animal&gt; getAnimalsByType(AnimalType type) { &#8230; [&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-25375","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25375","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=25375"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25375\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}