{"id":7164,"date":"2024-11-14T15:39:31","date_gmt":"2024-11-14T07:39:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7164\/"},"modified":"2024-11-14T15:39:31","modified_gmt":"2024-11-14T07:39:31","slug":"%e5%9c%a8-spring-boot-%e4%b8%ad%e9%93%be%e6%8e%a5-mysql-%e6%97%b6%ef%bc%8c-mybatis-%e6%96%b9%e6%b3%95%e4%b8%ad%e7%94%a8%e7%a1%ac%e7%bc%96%e7%a0%81%e8%bf%98%e6%98%af%e5%8f%82%e6%95%b0%e4%bc%a0%e9%80%92","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7164\/","title":{"rendered":"\u5728 Spring Boot \u4e2d\u94fe\u63a5 MySQL \u65f6\uff0c MyBatis \u65b9\u6cd5\u4e2d\u7528\u786c\u7f16\u7801\u8fd8\u662f\u53c2\u6570\u4f20\u9012\u66f4\u5408\u9002\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173054826326382.jpg\" class=\"aligncenter\" title=\"\u5728 Spring Boot \u4e2d\u94fe\u63a5 MySQL \u65f6\uff0c MyBatis \u65b9\u6cd5\u4e2d\u7528\u786c\u7f16\u7801\u8fd8\u662f\u53c2\u6570\u4f20\u9012\u66f4\u5408\u9002\uff1f\u63d2\u56fe\" alt=\"\u5728 Spring Boot \u4e2d\u94fe\u63a5 MySQL \u65f6\uff0c MyBatis \u65b9\u6cd5\u4e2d\u7528\u786c\u7f16\u7801\u8fd8\u662f\u53c2\u6570\u4f20\u9012\u66f4\u5408\u9002\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 Spring Boot \u4e2d\u94fe\u63a5 MySQL \u65f6\uff0c\u9700\u8981\u6ce8\u610f\u7684 MyBatis \u95ee\u9898<\/strong><\/p>\n<p>\u4e00\u3001\u80cc\u666f<\/p>\n<p>\u5047\u8bbe\u5b58\u5728\u4e00\u4e2a\u540d\u4e3a &#8220;animal&#8221; \u7684 SQL \u8868\uff0c\u5176\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5217\u540d<\/th>\n<th>\u7c7b\u578b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>id<\/td>\n<td>\u6574\u6570<\/td>\n<\/tr>\n<tr>\n<td>name<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<\/tr>\n<tr>\n<td>type<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<\/tr>\n<tr>\n<td>age<\/td>\n<td>\u6574\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8868\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>name<\/th>\n<th>type<\/th>\n<th>age<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u767d\u80d6<\/td>\n<td>cat<\/td>\n<td>12<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u6cf0\u54e5<\/td>\n<td>cat<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u5927G<\/td>\n<td>dog<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u58a8\u5b9d<\/td>\n<td>sheep<\/td>\n<td>6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e8c\u3001\u95ee\u9898<\/p>\n<p>\u7f16\u5199\u4e00\u4e2a MyBatis \u65b9\u6cd5 queryCatFromXXX()\uff0c\u4ece &#8220;animal&#8221; \u8868\u4e2d\u83b7\u53d6\u6240\u6709\u7c7b\u578b\u4e3a &#8220;cat&#8221; \u7684\u6570\u636e\u3002\u5728 SQL \u8bed\u53e5\u4e2d\uff0c\u6761\u4ef6 &#8220;type=cat&#8221; \u53ef\u4ee5\uff1a<\/p>\n<ul>\n<li> <strong>\u786c\u7f16\u7801\u5728 SQL \u4e2d<\/strong>\uff1aselect * from animal where type=&#8221;cat&#8221;<\/li>\n<li> <strong>\u901a\u8fc7\u53c2\u6570\u4f20\u9012<\/strong>\uff1aselect * from animal where type=#{type}<\/li>\n<\/ul>\n<p>\u90a3\u4e48\uff0c\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\uff0c\u54ea\u79cd\u505a\u6cd5\u66f4\u5408\u9002\uff1a<\/p>\n<ul>\n<li>\u65b9\u6cd5\u660e\u786e\u7528\u4e8e\u67e5\u8be2 &#8220;cat&#8221; \u76f8\u5173\u6570\u636e<\/li>\n<li>\u5b58\u5728\u66f4\u7075\u6d3b\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u67e5\u8be2\u4e0d\u540c\u7c7b\u578b\u7684\u52a8\u7269\u6570\u636e<\/li>\n<\/ul>\n<p>\u4e09\u3001\u7b54\u6848<\/p>\n<p>\u63a8\u8350\u5728 MyBatis \u65b9\u6cd5\u4e2d\u901a\u8fc7 <strong>\u4f20\u9012 type \u53c2\u6570\u6765\u83b7\u53d6\u6570\u636e<\/strong>\u3002<\/p>\n<p>\u5728 <strong>Service \u5c42<\/strong>\u8003\u8651\u662f\u5426\u9700\u8981\u66f4\u7075\u6d3b\u7684\u65b9\u6cd5\uff0c\u6bd4\u5982\u6839\u636e\u7c7b\u578b\u679a\u4e3e\u83b7\u53d6\u6570\u636e\u3002\u5982\u679c\u9700\u8981\uff1a<\/p>\n<ul>\n<li>\u5728 Service \u5c42\u521b\u5efa\u4e00\u4e2a\u65b9\u6cd5\uff0c\u4f20\u5165\u7c7b\u578b\u679a\u4e3e\u53c2\u6570\u3002<\/li>\n<li>\u5728\u65b9\u6cd5\u5185\u90e8\uff0c\u6839\u636e\u7c7b\u578b\u679a\u4e3e\u6784\u5efa\u67e5\u8be2\u6761\u4ef6\u3002<\/li>\n<li>Controller \u76f4\u63a5\u8c03\u7528\u65b9\u6cd5\uff0c\u4f20\u5165 &#8220;cat&#8221; \u503c\u679a\u4e3e\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u4e0d\u9700\u8981\u66f4\u7075\u6d3b\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728 Service \u5c42\u521b\u5efa\u7279\u5b9a\u65b9\u6cd5\uff0c\u5982\u83b7\u53d6\u8f6c\u79fb\u52a8\u7269\u6570\u636e\u3002\u8be5\u65b9\u6cd5\u5185\u90e8\u5b9e\u73b0\u6761\u4ef6\u7b5b\u9009\uff0c\u8c03\u7528\u8005\u76f4\u63a5\u8c03\u7528\u65b9\u6cd5\u5373\u53ef\u83b7\u53d6\u9700\u8981\u8f6c\u79fb\u52a8\u7269\u7684\u6570\u636e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728 Spring Boot \u4e2d\u94fe\u63a5 MySQL \u65f6\uff0c MyBatis \u65b9\u6cd5\u4e2d\u7528\u786c\u7f16\u7801\u8fd8\u662f\u53c2\u6570\u4f20\u9012\u66f4\u5408\u9002\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>\u5728 Spring Boot \u4e2d\u94fe\u63a5 MySQL \u65f6\uff0c\u9700\u8981\u6ce8\u610f\u7684 MyBatis \u95ee\u9898 \u4e00\u3001\u80cc\u666f \u5047\u8bbe\u5b58\u5728\u4e00\u4e2a\u540d\u4e3a &#8220;animal&#8221; \u7684 SQL \u8868\uff0c\u5176\u7ed3\u6784\u5982\u4e0b\uff1a \u5217\u540d \u7c7b\u578b id \u6574\u6570 name \u5b57\u7b26\u4e32 type \u5b57\u7b26\u4e32 age \u6574\u6570 \u8868\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a id name type age 1 \u767d\u80d6 cat 12 2 \u6cf0\u54e5 cat 10 3 \u5927G dog 9 4 \u58a8\u5b9d sheep 6 \u4e8c\u3001\u95ee\u9898 \u7f16\u5199\u4e00\u4e2a MyBatis \u65b9\u6cd5 queryCatFromXXX()\uff0c\u4ece &#8220;animal&#8221; \u8868\u4e2d\u83b7\u53d6\u6240\u6709\u7c7b\u578b\u4e3a &#8220;cat&#8221; \u7684\u6570\u636e\u3002\u5728 SQL [&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-7164","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7164","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=7164"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7164\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}