{"id":875,"date":"2023-03-03T00:20:59","date_gmt":"2023-03-02T16:20:59","guid":{"rendered":"https:\/\/explause.com\/?p=875"},"modified":"2023-03-03T00:56:10","modified_gmt":"2023-03-02T16:56:10","slug":"spring-boot%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/devdoge.org\/?p=875","title":{"rendered":"Spring Boot\u5165\u95e8"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u76f8\u5bf9\u4e8eSpring\u7684\u8fdb\u6b65\u662f\u652f\u6301\u81ea\u52a8\u914d\u7f6e\uff0c\u652f\u6301\u6d4b\u8bd5\uff0c\u4e0d\u9700\u8981\u5bb9\u5668\uff0c\u4e5f\u4e0d\u9700\u8981XML\u914d\u7f6e\u7b49\u65b0\u7279\u6027\u3002<br>Spring Boot\u9879\u76ee\u53ef\u4ee5\u6253\u5305\u6210Jar\u6587\u4ef6\uff0c\u5185\u90e8\u96c6\u6210\u4e86tomcat\u6216\u8005\u522b\u7684\u670d\u52a1\u5668\u3002<br>Spring Boot\u4e3b\u8981\u4f7f\u7528RESTful\u63a5\u53e3\uff0c\u4f7f\u7528JSON\u8fdb\u884c\u6570\u636e\u4ea4\u4e92\uff0c\u7528\u4e8e<strong>\u524d\u540e\u7aef\u5206\u79bb<\/strong>\u7684\u8bbe\u8ba1\u6a21\u5f0f\u3002<br>Spring Boot\u4f7f\u7528\u4e0a\u5176\u5b9e\u5341\u5206\u7b80\u5355\uff0c\u51e0\u4e4e\u4e0d\u9700\u8981XML\u914d\u7f6e\uff08\u9664\u4e86\u6dfb\u52a0\u4f9d\u8d56\u7684\u5e93\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b0\u5efaSpringBoot\u9879\u76ee\u5728<a href=\"https:\/\/start.spring.io\/\">\u5b98\u7f51\u4e0a<\/a>\u5f88\u8f7b\u677e\u5730\u521b\u5efa\u5e76\u6dfb\u52a0\u90e8\u5206\u4f9d\u8d56\uff0c\u4f7f\u7528Eclipse IDE\u53ef\u4ee5\u53c2\u8003<a href=\"https:\/\/explause.com\/?p=221\">\u524d\u9762\u7684\u6587\u7ae0<\/a>\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">@SpringBootApplication\u6ce8\u89e3<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u8bf4\u4e00\u4e2aSpringBoot\u5e94\u7528\u5c31\u662f\u56f4\u7ed5\u7740\u8fd9\u4e2a\u6ce8\u89e3\u5f00\u59cb\u7684\u3002<br>\u5b83\u7684\u5b9a\u4e49\u5305\u542b\u4e09\u4e2a\u6ce8\u89e3\uff1a@EnableAutoConfiguration\u3001@ComponentScan\u548c@SpringBootConfiguration\u3002<br>\u5c31\u662f\u8fd9\u4e9b\u6ce8\u89e3\u5f00\u542f\u4e86\u81ea\u52a8\u914d\u7f6e\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u6784\u5efa\u7cfb\u7edf<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">SpringBoot\u540c\u65f6\u652f\u6301<strong>Maven<\/strong>\u548c<strong>Gradle<\/strong>\uff0c\u540c\u65f6\u4e5f\u662f\u4f9d\u8d56\u7ba1\u7406\u7cfb\u7edf\u3002<br>\u4f7f\u7528SpringBoot\u65f6\u4f1a\u770b\u89c1\u4e00\u4e9b\u50cfspring-boot-starter-data-jpa\u4e00\u6837\u7684\u4f9d\u8d56\uff0c\u8fd9\u662f<strong>\u4fbf\u6377\u7684\u4f9d\u8d56\u63cf\u8ff0\u7b26<\/strong>\u3002<br>\u5b98\u65b9\u7684starter\u90fd\u662f<strong>spring-boot-starter-<\/strong>*\u547d\u540d\u89c4\u5219\u5f00\u5934\u7684\u3002<br>\u7f16\u8f91pom.xml\u6587\u4ef6\u65f6\u53ef\u4ee5\u901a\u8fc7<strong>ctrl-space<\/strong>\u7ec4\u5408\u952e\u5f39\u51fa\u81ea\u52a8\u8865\u5168\u83dc\u5355\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/explause.com\/wp-content\/uploads\/2023\/03\/starter.png\" alt=\"\" class=\"wp-image-888\" width=\"354\" height=\"272\" srcset=\"https:\/\/devdoge.org\/wp-content\/uploads\/2023\/03\/starter.png 496w, https:\/\/devdoge.org\/wp-content\/uploads\/2023\/03\/starter-300x230.png 300w\" sizes=\"auto, (max-width: 354px) 100vw, 354px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">\u4ee3\u7801\u7ed3\u6784<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b0\u521b\u5efa\u7684\u9879\u76ee\u4f1a\u6709\u4e00\u4e2a\u4e3b\u5e94\u7528\u7c7b\uff0c\u5185\u542bmain\u65b9\u6cd5\u3002\u76f4\u63a5\u8fd0\u884c\u8fd9\u4e2a\u7c7b\u5c31\u80fd\u542f\u52a8Spring Boot\u9879\u76ee\u3002<br>\u4ee5\u8fd9\u4e2a\u7c7b\u6240\u5728\u7684\u5305\u4e3a\u6839\u8282\u70b9\uff0c\u521b\u5efa\u65b0\u7684\u7c7b\u548c\u5305\u3002<\/p>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-995f960e wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<figure class=\"wp-block-image alignleft size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/explause.com\/wp-content\/uploads\/2023\/03\/structure.png\" alt=\"\" class=\"wp-image-889\" width=\"254\" height=\"245\" srcset=\"https:\/\/devdoge.org\/wp-content\/uploads\/2023\/03\/structure.png 357w, https:\/\/devdoge.org\/wp-content\/uploads\/2023\/03\/structure-300x290.png 300w\" sizes=\"auto, (max-width: 254px) 100vw, 254px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image alignright size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/explause.com\/wp-content\/uploads\/2023\/03\/main.png\" alt=\"\" class=\"wp-image-890\" width=\"341\" height=\"155\" srcset=\"https:\/\/devdoge.org\/wp-content\/uploads\/2023\/03\/main.png 640w, https:\/\/devdoge.org\/wp-content\/uploads\/2023\/03\/main-300x137.png 300w\" sizes=\"auto, (max-width: 341px) 100vw, 341px\" \/><\/figure>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<h4 class=\"wp-block-heading\">\u914d\u7f6e\u7c7b<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Spring Boot\u504f\u5411\u4e8e\u4f7f\u7528Java\u914d\u7f6e\uff0c\u4f46\u662f\u4f7f\u7528XML\u914d\u7f6e\u4e5f\u662f\u5141\u8bb8\u7684\u3002<br>@Configuration\u6ce8\u89e3\u5e94\u7528\u4e8e\u4e00\u4e2a\u7c7b\uff0c\u5c31\u662f\u914d\u7f6e\u7c7b\u3002\u53ef\u4ee5\u4f7f\u7528@Import\u6ce8\u89e3\u5bfc\u5165\u989d\u5916\u7684\u914d\u7f6e\u7c7b\u3002<br>\u5728Spring Boot\u4e2d\u4f7f\u7528XML\u914d\u7f6e\u53ef\u4ee5\u5148\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u7c7b\u540e\u4f7f\u7528@ImportResource\u6ce8\u89e3\u8f7d\u5165XML\u914d\u7f6e\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u81ea\u52a8\u914d\u7f6e<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">SpringBoot\u652f\u6301\u6839\u636e\u6dfb\u52a0\u7684\u4f9d\u8d56\u81ea\u52a8\u914d\u7f6e\u5e94\u7528\u3002<br>\u6bd4\u5982\u6dfb\u52a0\u4e86h2 database\u7684\u4f9d\u8d56\u5c31\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u5185\u5b58\u6570\u636e\u5e93\uff0c\u5e76\u6267\u884cclasspath\u4e0b\u7684schema.sql\u548cdata.sql<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><a href=\"https:\/\/explause.com\/wp-content\/uploads\/2023\/03\/cruddemo.zip\">\u5b9e\u4f8b\u4e0b\u8f7d<\/a><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u505a\u540e\u7aef\u6700\u57fa\u672c\u7684\u5c31\u662f\u589e\u5220\u6539\u67e5\uff08CRUD\uff09\uff0c\u90a3\u5c31\u56f4\u7ed5\u8fd9\u4e00\u4e3b\u9898\u505a\u4e2ademo\uff0c\u53ef\u4ee5\u66f4\u597d\u4e86\u89e3\u600e\u4e48\u6784\u5efa\u5e94\u7528\u3002<br>\u4f7f\u7528SpringBoot\u3001MyBatis\u548cH2 database\u505a\u4e00\u4e2a\u6a21\u578b\uff0cController\u5c42\u3001Service\u5c42\u548cDao\u5c42\u4e09\u5c42\u7ed3\u6784\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Controller\u4f7f\u7528@RestController\u7528\u4e8e\u7c7b\uff0c\u7136\u540e@Get\/Post\/Put\/DeleteMapping\u6ce8\u89e3\u5e94\u7528\u4e8e\u65b9\u6cd5\u4f5c\u4e3aweb\u8bbf\u95ee\u7aef\u70b9\uff0c\u4f7f\u7528@Autowired\u8fdb\u884c\u4f9d\u8d56\u6ce8\u5165\uff0c@Service\u6ce8\u89e3\u8bf4\u660e\u670d\u52a1\u6587\u4ef6\uff0c\u4f7f\u7528MyBatis\u6846\u67b6\u5c31\u4f1a\u7528\u5230@Mapper\u6ce8\u89e3\uff0c\u4e0d\u7528xml\u6620\u5c04\u5c31\u4f1a\u7528\u5230@Insert\u3001@Update\u3001@Select\u548c@Delete\u7b49\u6ce8\u89e3\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u4e86lombok\u51cf\u5c11\u91cd\u590d\u52b3\u52a8\uff0c\u5982\u679cEclipse\u6ca1\u6709\u5b89\u88c5\u5c31\u8981\u5148<a href=\"https:\/\/explause.com\/?p=896\">\u5b89\u88c5Lombok<\/a>\u624d\u80fd\u8fd0\u884c\u3002<br>\u8bf4\u8d77\u6765\u7b80\u5355\uff0c\u4e0d\u5982\u4e0b\u8f7d\u4e0b\u6765\u8dd1\u8dd1\u770b\uff0c\u6bd4\u770b\u7684\u5370\u8c61\u6df1\u523b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SpringBoot\u7b80\u5355\u6613\u7528\uff0c\u4e0a\u624b\u7b80\u5355\uff0c\u4f46\u662f\u81ea\u5df1\u5b9e\u9645\u8dd1\u8d77\u6765\u5370\u8c61\u4f1a\u66f4\u6df1\u523b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[33],"class_list":["post-875","post","type-post","status-publish","format-standard","hentry","category-springboot","tag-springboot"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/devdoge.org\/index.php?rest_route=\/wp\/v2\/posts\/875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devdoge.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devdoge.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devdoge.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/devdoge.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=875"}],"version-history":[{"count":17,"href":"https:\/\/devdoge.org\/index.php?rest_route=\/wp\/v2\/posts\/875\/revisions"}],"predecessor-version":[{"id":904,"href":"https:\/\/devdoge.org\/index.php?rest_route=\/wp\/v2\/posts\/875\/revisions\/904"}],"wp:attachment":[{"href":"https:\/\/devdoge.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devdoge.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devdoge.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}