{"id":307706,"date":"2024-05-20T20:42:27","date_gmt":"2024-05-20T12:42:27","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/307706.html"},"modified":"2024-05-20T20:42:43","modified_gmt":"2024-05-20T12:42:43","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-30-%e5%88%86%e9%92%9f%e5%bf%ab%e9%80%9f%e4%b8%8a%e6%89%8b%e4%bb%8e-0-%e6%90%ad%e5%bb%ba-spring-boot-%e9%a1%b9%e7%9b%ae","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/307706.html","title":{"rendered":"\u5982\u4f55\u5728 30 \u5206\u949f\u5feb\u901f\u4e0a\u624b\u4ece 0 \u642d\u5efa Spring boot  \u9879\u76ee"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26224043\/bd3b383c-5671-4aa6-860c-a5d7b58d8b7a.webp\" alt=\"\u5982\u4f55\u5728 30 \u5206\u949f\u5feb\u901f\u4e0a\u624b\u4ece 0 \u642d\u5efa Spring boot  \u9879\u76ee\" \/><\/p>\n<p><p>\u5feb\u901f\u4e0a\u624b\u642d\u5efaSpring Boot\u9879\u76ee\uff0c\u5173\u952e\u5728\u4e8e\u7406\u89e3Spring Boot\u7684\u6838\u5fc3\u7279\u6027\u3001\u914d\u7f6e\u5de5\u5177\u7684\u4f7f\u7528\u3001\u4f9d\u8d56\u7ba1\u7406\u4ee5\u53ca\u9879\u76ee\u7684\u6784\u5efa\u548c\u8fd0\u884c\u3002<strong>\u6838\u5fc3\u6b65\u9aa4\u5305\u62ec\uff1a\u5b89\u88c5\u5fc5\u8981\u7684\u5f00\u53d1\u5de5\u5177\u3001\u4f7f\u7528Spring Initializr\u751f\u6210\u9879\u76ee\u9aa8\u67b6\u3001\u914d\u7f6eapplication.properties\u6587\u4ef6\u3001\u521b\u5efa\u57fa\u672c\u7684MVC\u7ed3\u6784\u3001\u4ee5\u53ca\u8fd0\u884c\u548c\u6d4b\u8bd5\u4f60\u7684\u5e94\u7528\u3002<\/strong> \u7279\u522b\u5730\uff0c\u4f7f\u7528Spring Initializr\u6765\u751f\u6210\u9879\u76ee\u9aa8\u67b6\u662f\u4e00\u4e2a\u6781\u5927\u5730\u7b80\u5316\u4e86\u9879\u76ee\u521d\u59cb\u5316\u8fc7\u7a0b\u7684\u65b9\u6cd5\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u901a\u8fc7\u4e00\u4e2a\u7b80\u6613\u7684\u56fe\u5f62\u754c\u9762\u9009\u62e9\u6240\u9700\u7684\u4f9d\u8d56\u3001\u9879\u76ee\u5143\u6570\u636e\u4ee5\u53ca\u5176\u4ed6\u914d\u7f6e\uff0c\u751f\u6210\u4e00\u4e2a\u53ef\u4ee5\u7acb\u5373\u5bfc\u5165IDE\u7684\u9879\u76ee\u7ed3\u6784\u3002\u8fd9\u4e00\u6b65\u4e0d\u4ec5\u8282\u7701\u4e86\u914d\u7f6e\u65f6\u95f4\uff0c\u8fd8\u964d\u4f4e\u4e86\u521d\u5b66\u8005\u5728\u9879\u76ee\u8bbe\u7f6e\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u9047\u5230\u7684\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u5f00\u53d1\u5de5\u5177<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u642d\u5efaSpring Boot\u9879\u76ee\u4e4b\u524d\uff0c\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Java\u5f00\u53d1\u73af\u5883\uff08\u901a\u5e38\u662fJDK\uff09\u548c\u4e00\u4e2a\u9002\u5408\u7684IDE\uff08\u5982IntelliJ IDEA\u3001Eclipse\u6216VS Code\uff09\u3002Java\u662fSpring Boot\u7684\u57fa\u7840\uff0c\u800c\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684IDE\u5c06\u4e3a\u4f60\u63d0\u4f9b\u4ee3\u7801\u81ea\u52a8\u5b8c\u6210\u3001<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/23316.html\" target=\"_blank\">\u9879\u76ee\u7ba1\u7406<\/a>\u3001\u7248\u672c\u63a7\u5236\u7b49\u4fbf\u5229\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684JDK\uff0c\u786e\u4fdd\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u6b63\u786e\uff0c\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165<code>java -version<\/code>\u6765\u9a8c\u8bc1\u5b89\u88c5\u3002\u9009\u62e9IDE\u65f6\uff0c\u63a8\u8350\u4f7f\u7528\u652f\u6301Spring Boot\u7684IDE\uff0c\u5982IntelliJ IDEA\uff0c\u5176\u4e2d\u7684Spring Initializr\u63d2\u4ef6\u80fd\u6781\u5927\u7b80\u5316\u642d\u5efa\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Spring Initializr\u751f\u6210\u9879\u76ee\u9aa8\u67b6<\/h3>\n<\/p>\n<p><p>Spring Initializr\u662f\u4e00\u4e2a\u5728\u7ebf\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5feb\u901f\u751f\u6210Spring Boot\u9879\u76ee\u7684\u521d\u59cb\u7ed3\u6784\u3002\u8bbf\u95ee\u5176\u5b98\u65b9\u7f51\u7ad9\uff0c\u4f60\u53ef\u4ee5\u81ea\u5b9a\u4e49\u9879\u76ee\u7684\u57fa\u672c\u5c5e\u6027\uff08\u5982Group\u3001Artifact\u3001Dependencies\u7b49\uff09\u3002<\/p>\n<\/p>\n<p><p>\u8fdb\u5165Spring Initializr\u7684\u9875\u9762\u540e\uff0c\u586b\u5199\u9879\u76ee\u7684Group\u548cArtifact\u3002Group\u901a\u5e38\u662f\u4f60\u7684\u7ec4\u7ec7\u6216\u5305\u7684\u540d\u79f0\uff0cArtifact\u662f\u9879\u76ee\u7684\u540d\u79f0\u3002\u63a5\u7740\uff0c\u6dfb\u52a0\u4f60\u9884\u8ba1\u4f1a\u7528\u5230\u7684\u4f9d\u8d56\uff0c\u4f8b\u5982Spring Web\u3001Spring Data JPA\u7b49\u3002\u5b8c\u6210\u540e\uff0c\u70b9\u51fb\u751f\u6210\uff0c\u4e0b\u8f7d\u9879\u76ee\u538b\u7f29\u5305\uff0c\u5e76\u89e3\u538b\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u914d\u7f6eapplication.properties\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>Spring Boot\u901a\u8fc7<code>application.properties<\/code>\u6587\u4ef6\u7b80\u5316\u4e86\u5f88\u591a\u539f\u672c\u590d\u6742\u7684\u914d\u7f6e\u3002\u5728\u8be5\u6587\u4ef6\u4e2d\uff0c\u4f60\u53ef\u4ee5\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u3001\u670d\u52a1\u5668\u7aef\u53e3\u53f7\u7b49\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u4f60\u7684\u9879\u76ee\u5bfc\u5165IDE\u540e\uff0c\u627e\u5230<code>src\/m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n\/resources\/application.properties<\/code>\u6587\u4ef6\uff0c\u5f00\u59cb\u8fdb\u884c\u5fc5\u8981\u7684\u914d\u7f6e\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u9879\u76ee\u9700\u8981\u8fde\u63a5\u6570\u636e\u5e93\uff0c\u5219\u9700\u8981\u5728\u6b64\u6587\u4ef6\u4e2d\u914d\u7f6e\u6570\u636e\u5e93\u7684URL\u3001\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u521b\u5efa\u57fa\u672c\u7684MVC\u7ed3\u6784<\/h3>\n<\/p>\n<p><p>Spring Boot\u9075\u5faaMVC\uff08Model-View-Controller\uff09\u67b6\u6784\u6a21\u5f0f\uff0c\u56e0\u6b64\uff0c\u521b\u5efa\u4e00\u4e2a\u63a7\u5236\u5668\uff08Controller\uff09\u662f\u5f00\u59cb\u7684\u597d\u65b9\u5f0f\u3002\u5728<code>src\/main\/java<\/code>\u4e0b\uff0c\u65b0\u5efa\u4e00\u4e2a\u5305\uff0c\u5e76\u5728\u5305\u5185\u521b\u5efa\u4e00\u4e2a\u7c7b\uff0c\u6807\u6ce8<code>@RestController<\/code>\u6ce8\u89e3\u6765\u5b9a\u4e49\u4e00\u4e2a\u63a7\u5236\u5668\uff0c\u518d\u4f7f\u7528<code>@RequestMapping<\/code>\u6ce8\u89e3\u5b9a\u4e49\u8bbf\u95ee\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u6a21\u578b\uff08Model\uff09\uff0c\u6a21\u578b\u7c7b\u901a\u5e38\u662f\u7b80\u5355\u7684JavaBeans\uff0c\u7528\u4e8e\u5c01\u88c5\u6570\u636e\u3002\u5982\u679c\u4f60\u7684\u5e94\u7528\u5229\u7528\u4e86\u6570\u636e\u5e93\uff0c\u90a3\u4e48\u5728\u6a21\u578b\u7c7b\u4e2d\u4f7f\u7528JPA\u6ce8\u89e3\u5b9a\u4e49\u5b9e\u4f53\u548c\u6570\u636e\u5e93\u8868\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\u662f\u5fc5\u8981\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u8fd0\u884c\u548c\u6d4b\u8bd5\u4f60\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5f53\u57fa\u672c\u7ed3\u6784\u642d\u5efa\u5b8c\u6210\u540e\uff0c\u5c31\u53ef\u4ee5\u8fd0\u884c\u4f60\u7684Spring Boot\u5e94\u7528\u4e86\u3002\u5728IDE\u4e2d\uff0c\u627e\u5230\u9879\u76ee\u7684\u4e3b\u7c7b\uff0c\u901a\u5e38\u4f1a\u6709<code>@SpringBootApplication<\/code>\u6ce8\u89e3\uff0c\u53f3\u952e\u70b9\u51fb\u5e76\u9009\u62e9\u8fd0\u884c\u3002Spring Boot\u5185\u7f6e\u4e86Tomcat\u4f5c\u4e3a\u9ed8\u8ba4\u7684Servlet\u5bb9\u5668\uff0c\u6240\u4ee5\u65e0\u9700\u989d\u5916\u914d\u7f6e\u5373\u53ef\u542f\u52a8Web\u670d\u52a1\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u9a8c\u8bc1\u4f60\u7684\u5e94\u7528\u662f\u5426\u6210\u529f\u8fd0\u884c\uff0c\u53ef\u4ee5\u7f16\u5199\u4e00\u4e9b\u7b80\u5355\u7684\u5355\u5143\u6d4b\u8bd5\uff0c\u6216\u8005\u4f7f\u7528Postman\u8fd9\u7c7b\u5de5\u5177\u8fdb\u884cAPI\u63a5\u53e3\u6d4b\u8bd5\u3002Spring Boot\u4e5f\u63d0\u4f9b\u4e86<code>@SpringBootTest<\/code>\u6ce8\u89e3\u6765\u652f\u6301\u96c6\u6210\u6d4b\u8bd5\uff0c\u786e\u4fdd\u5e94\u7528\u7684\u5404\u4e2a\u90e8\u5206\u80fd\u591f\u6b63\u5e38\u534f\u4f5c\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u9075\u5faa\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5373\u4f7f\u662f\u521d\u5b66\u8005\u4e5f\u80fd\u5728\u77ed\u65f6\u95f4\u5185\u4e0a\u624b\u642d\u5efa\u4e00\u4e2aSpring Boot\u9879\u76ee\u3002\u638c\u63e1Spring Boot\u4e0d\u4ec5\u4ec5\u662f\u5b66\u4e60\u5982\u4f55\u642d\u5efa\u9879\u76ee\u90a3\u4e48\u7b80\u5355\uff0c\u8fd8\u5305\u542b\u4e86\u7406\u89e3\u5176\u80cc\u540e\u7684\u8bbe\u8ba1\u54f2\u5b66\u3001\u6df1\u5165\u5b66\u4e60\u5176\u63d0\u4f9b\u7684\u5404\u79cd\u529f\u80fd\u4ee5\u53ca\u5982\u4f55\u5c06\u8fd9\u4e9b\u529f\u80fd\u5e94\u7528\u5230\u5b9e\u9645\u5f00\u53d1\u4e2d\u53bb\u3002\u8fd9\u9700\u8981\u65f6\u95f4\u548c\u5b9e\u8df5\u7684\u79ef\u7d2f\uff0c\u4f46\u4ece\u96f6\u5f00\u59cb\u642d\u5efa\u9879\u76ee\u65e0\u7591\u662f\u4e00\u4e2a\u6781\u597d\u7684\u8d77\u70b9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1.<\/strong> <strong>\u5982\u4f55\u5feb\u901f\u642d\u5efa\u4e00\u4e2a\u57fa\u672c\u7684Spring Boot\u9879\u76ee\uff1f<\/strong><\/p>\n<p>\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u6765\u5feb\u901f\u642d\u5efa\u4e00\u4e2a\u57fa\u672c\u7684Spring Boot\u9879\u76ee\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u4e0b\u8f7d\u5e76\u5b89\u88c5Java JDK\uff0c\u5e76\u8bbe\u7f6e\u597dJava\u73af\u5883\u53d8\u91cf\u3002<\/li>\n<li>\u5176\u6b21\uff0c\u5b89\u88c5\u4e00\u4e2aIDE\uff0c\u5982Eclipse\u6216IntelliJ IDEA\uff0c\u7528\u4e8e\u7f16\u5199\u548c\u7ba1\u7406\u9879\u76ee\u3002<\/li>\n<li>\u7136\u540e\uff0c\u6253\u5f00IDE\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Spring Boot\u9879\u76ee\u3002<\/li>\n<li>\u6700\u540e\uff0c\u6839\u636e\u9879\u76ee\u9700\u6c42\uff0c\u914d\u7f6e\u76f8\u5173\u7684\u4f9d\u8d56\u548c\u8bbe\u7f6e\uff0c\u5e76\u7f16\u5199\u4ee3\u7801\u5b9e\u73b0\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p><strong>2.<\/strong> <strong>Spring Boot\u9879\u76ee\u4e2d\u5982\u4f55\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\uff1f<\/strong><\/p>\n<p>\u5728Spring Boot\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u76f8\u5e94\u7684\u6570\u636e\u5e93\u8fde\u63a5\u53c2\u6570\u6765\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u6253\u5f00\u9879\u76ee\u7684\u914d\u7f6e\u6587\u4ef6\uff08\u5982application.properties\u6216application.yml\uff09\u3002<\/li>\n<li>\u5176\u6b21\uff0c\u6839\u636e\u6240\u4f7f\u7528\u7684\u6570\u636e\u5e93\u7c7b\u578b\uff0c\u8bbe\u7f6e\u5bf9\u5e94\u7684\u8fde\u63a5\u53c2\u6570\uff0c\u5982\u6570\u636e\u5e93URL\u3001\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002<\/li>\n<li>\u7136\u540e\uff0c\u6839\u636e\u9700\u8981\u914d\u7f6e\u8fde\u63a5\u6c60\u7684\u76f8\u5173\u53c2\u6570\uff0c\u5982\u6700\u5927\u8fde\u63a5\u6570\u3001\u6700\u5c0f\u8fde\u63a5\u6570\u7b49\u3002<\/li>\n<li>\u6700\u540e\uff0c\u4fdd\u5b58\u914d\u7f6e\u6587\u4ef6\u5e76\u91cd\u542f\u9879\u76ee\uff0c\u5e94\u7528\u5373\u53ef\u4f7f\u7528\u6240\u914d\u7f6e\u7684\u6570\u636e\u5e93\u8fde\u63a5\u3002<\/li>\n<\/ul>\n<p><strong>3.<\/strong> <strong>\u5982\u4f55\u4f7f\u7528Spring Boot\u5b9e\u73b0RESTful API\u63a5\u53e3\uff1f<\/strong><\/p>\n<p>\u8981\u4f7f\u7528Spring Boot\u5b9e\u73b0RESTful API\u63a5\u53e3\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u5728\u9879\u76ee\u4e2d\u521b\u5efa\u4e00\u4e2a\u63a7\u5236\u5668\u7c7b\uff0c\u8be5\u7c7b\u8d1f\u8d23\u5904\u7406\u63a5\u53e3\u8bf7\u6c42\u548c\u54cd\u5e94\u3002<\/li>\n<li>\u5176\u6b21\uff0c\u4f7f\u7528\u6ce8\u89e3\u6807\u8bb0\u63a7\u5236\u5668\u7c7b\u548c\u5177\u4f53\u7684\u5904\u7406\u65b9\u6cd5\uff0c\u5982@RequestMapping\u3001@GetMapping\u7b49\u3002<\/li>\n<li>\u7136\u540e\uff0c\u5728\u5904\u7406\u65b9\u6cd5\u4e2d\u7f16\u5199\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\uff0c\u5e76\u8fd4\u56de\u76f8\u5e94\u7684\u6570\u636e\u6216\u9519\u8bef\u4fe1\u606f\u3002<\/li>\n<li>\u6700\u540e\uff0c\u4fdd\u5b58\u5e76\u8fd0\u884c\u9879\u76ee\uff0c\u901a\u8fc7\u8bbf\u95ee\u76f8\u5e94\u7684URL\u5730\u5740\u5373\u53ef\u6d4b\u8bd5\u548c\u4f7f\u7528RESTful API\u63a5\u53e3\u3002<\/li>\n<\/ul>\n<p>\u6ce8\u610f\uff1a\u5728\u7f16\u5199\u63a5\u53e3\u65f6\u5e94\u8be5\u9075\u5faaRESTful\u8bbe\u8ba1\u89c4\u8303\uff0c\u4f7f\u7528\u5408\u9002\u7684HTTP\u65b9\u6cd5\uff08\u5982GET\u3001POST\u3001PUT\u3001DELETE\uff09\u548cURL\u8def\u5f84\uff0c\u4ee5\u53ca\u8fd4\u56de\u5408\u9002\u7684\u72b6\u6001\u7801\u548c\u6570\u636e\u683c\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5feb\u901f\u4e0a\u624b\u642d\u5efaSpring Boot\u9879\u76ee\uff0c\u5173\u952e\u5728\u4e8e\u7406\u89e3Spring Boot\u7684\u6838\u5fc3\u7279\u6027\u3001\u914d\u7f6e\u5de5\u5177\u7684\u4f7f\u7528\u3001\u4f9d\u8d56\u7ba1\u7406 [&hellip;]","protected":false},"author":3,"featured_media":307727,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/307706"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=307706"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/307706\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/307727"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=307706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=307706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=307706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}