{"id":2661,"date":"2018-04-14T17:06:06","date_gmt":"2018-04-14T09:06:06","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2661"},"modified":"2018-04-14T17:06:06","modified_gmt":"2018-04-14T09:06:06","slug":"%e4%bd%bf%e7%94%a8-springboot-%e5%88%9b%e5%bb%ba-web-%e9%a1%b9%e7%9b%ae","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2661","title":{"rendered":"\u4f7f\u7528 SpringBoot \u521b\u5efa web \u9879\u76ee"},"content":{"rendered":"<p>\n\t\u8001\u5b9e\u8bf4\uff0cweb \u9879\u76ee\u548c\u975e web \u9879\u76ee\uff0c\u6ca1\u4ec0\u4e48\u5927\u7684\u533a\u522b\u3002\u65e0\u975e\u662f src\/main\/resources \u4e0b\u653e\u4e0d\u653e web \u9875\u9762\uff0cpom.xml \u4e2d\u662f\u5426\u5f15\u5165 spring-boot-starter-web \u6a21\u5757\u7684\u95ee\u9898\u3002\n<\/p>\n<p>\n\t\u5728\u4e0a\u4e00\u7bc7\u6587\u7ae0\u5f53\u4e2d\uff0c\u6211\u4eec\u8fd8\u6ca1\u6709\u5177\u4f53\u7684\u4ecb\u7ecd spring-boot-starter-web \uff0c\u56e0\u6b64\u672c\u6587\u6211\u4eec\u4e00\u5e76\u6765\u8bb2\u4e86\u3002\n<\/p>\n<p>\n\tSpringBoot \u521b\u5efa web \u9879\u76ee\u7684\u7b2c\u4e00\u6b65\uff0c\u5c31\u662f\u9700\u8981\u5f15\u5165&nbsp;spring-boot-starter-web \u6a21\u5757\uff0c\u7528\u6765\u652f\u6491 web \u7684\u4ea4\u4e92\u3002\n<\/p>\n<p>\n\tpom.xml \u4e2d\u6dfb\u52a0\u652f\u6301 web \u7684\u6a21\u5757\uff1a\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;dependency&gt;\r\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n    &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\r\n\t&lt;!-- \u4e1a\u4f59\u8349\uff1awww.xttblog.com --&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>\n\t\u4e5f\u6709\u4eba\u770b\u5230\uff0c\u7f51\u4e0a\u7684\u4e00\u4e9b\u9879\u76ee\u4e2d\u5f15\u5165\u4e86 spring-boot-starter-test \u3002\u90a3\u4e48 spring-boot-starter-test \u6a21\u5757\u6709\u4ec0\u4e48\u7528\u5462\uff1f\u5176\u5b9e\u770b\u540d\u5b57\u6211\u4eec\u5c31\u5e94\u8be5\u6e05\u695a\u3002\n<\/p>\n<ul>\n<li>\n\t\tspring-boot-starter \uff1a\u6838\u5fc3\u6a21\u5757\uff0c\u5305\u62ec\u81ea\u52a8\u914d\u7f6e\u652f\u6301\u3001\u65e5\u5fd7\u548cYAML\uff1b\n\t<\/li>\n<li>\n\t\tspring-boot-starter-test \uff1a\u6d4b\u8bd5\u6a21\u5757\uff0c\u5305\u62ecJUnit\u3001Hamcrest\u3001Mockito\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t\u7f16\u5199\u7b2c\u4e00\u4e2a Controller \u5b9e\u73b0 HelloWorld\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\n@RestController\r\npublic class HelloWorldController {\r\n    @RequestMapping(&quot;\/xttblog&quot;)\r\n    public String index() {\r\n        return &quot;Hello World&quot;;\r\n    }\r\n}<\/pre>\n<p>\n\t@RestController \u7684\u610f\u601d\u5c31\u662f controller \u91cc\u9762\u7684\u65b9\u6cd5\u90fd\u4ee5 json \u683c\u5f0f\u8f93\u51fa\uff0c\u4e0d\u7528\u518d\u5199\u4ec0\u4e48 jackjson \u914d\u7f6e\u7684\u4e86\uff01SpringBoot \u5c31\u662f\u8fd9\u4e48\u7b80\u5355\uff0c\u8fd9\u4e48\u4efb\u6027\u3002\n<\/p>\n<p>\n\t\u7136\u540e\u542f\u52a8 SpringBoot \u9879\u76ee\uff08\u8fd0\u884c @SpringBootApplication \u6ce8\u89e3\u7c7b\u7684 main\u65b9\u6cd5\uff09\u3002http:\/\/localhost:8080\/xttblog \u5c31\u770b\u5230\u8fd4\u56de\u4e86 HelloWorld\uff01\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"SpringBoot helloWorld\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/springboot\/master\/demo1\/6.png\" style=\"width: 407px;height: 206px\" \/>\n<\/p>\n<p>\n\t\u5230\u73b0\u5728\u4e3a\u6b62\uff0c\u6211\u4eec\u8fd8\u6ca1\u6709\u8df3\u8f6c\u5230\u5bf9\u5e94\u7684 web \u9875\u9762\u3002\u4e0b\u9762\u6211\u4eec\u7ee7\u7eed\u8ba9 Controller \u8df3\u8f6c\u5230\u5bf9\u5e94\u7684 web \u9875\u9762\u3002\n<\/p>\n<p>\n\tSpring Boot\u9ed8\u8ba4\u7684\u63d0\u4f9b\u7684\u9759\u6001\u6587\u4ef6\u914d\u7f6e\u8def\u5f84\u4f4d\u4e8eclasspath\u4e0b\uff0c\u76ee\u5f55\u540d\u79f0\u9700\u8981\u7b26\u5408\u4ee5\u4e0b\u89c4\u5b9a\uff1a\n<\/p>\n<ul>\n<li>\n\t\t\/static\n\t<\/li>\n<li>\n\t\t\/public\n\t<\/li>\n<li>\n\t\t\/resources\n\t<\/li>\n<li>\n\t\t\/META-INF\/resources\n\t<\/li>\n<\/ul>\n<p>\n\tSpring Boot\u9ed8\u8ba4\u63d0\u4f9b\u4e86\u591a\u79cd\u6a21\u677f\u5f15\u64ce\u7684\u652f\u6301\uff0c\u5982\uff1aThymeleaf\u3001Velocity\u3001FreeMarker\u7b49\u3002\u5c3d\u91cf\u4e0d\u8981\u5728Spring Boot\u4e2d\u4f7f\u7528JSP\uff0c\u5426\u5219\u5f88\u591a\u7279\u6027\u65e0\u6cd5\u4f7f\u7528\uff0c\u4e5f\u4f1a\u7834\u574f SringBoot \u7684\u521d\u8877\u3002\u5728Spring Boot\u4e2d\u9ed8\u8ba4\u7684\u6a21\u677f\u5f15\u64ce\u8def\u5f84\u662fsrc\/main\/resources\/templates\uff0c\u5f53\u7136\u6211\u4eec\u4e5f\u53ef\u4ee5\u4fee\u6539\u8fd9\u4e2a\u9ed8\u8ba4\u8def\u5f84\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"SpringBoot \u6a21\u677f\u5f15\u64ce\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/springboot\/master\/demo1\/5.png\" style=\"width: 628px;height: 564px\" \/>\n<\/p>\n<p>\n\t\u4ee5\u4e0a\u5c31\u662f SpringBoot \u7684 web \u76ee\u5f55\u7ed3\u6784\u3002\n<\/p>\n<p>\n\t\u7ec6\u5fc3\u7684\u670b\u53cb\u53d1\u73b0\uff0c\u6211\u4eec\u4e0a\u9762\u8bbf\u95ee xttblog \u7684\u56fe\u7247\u4e2d\u6ca1\u6709\u8d34\u51fa\u5730\u5740\u3002\u4e3a\u4ec0\u4e48\u5462\uff1f\u56e0\u4e3a\u8d34\u51fa\u5730\u5740\uff0c\u4f60\u4f1a\u53d1\u73b0\uff0cSpringboot \u9ed8\u8ba4\u7684\u8bbf\u95ee\u4e0d\u9700\u8981\u9879\u76ee\u540d\u5b57\u4e86\uff0c\u6211\u60f3\u52a0\u4e0a\u9879\u76ee\u540d\u5b57\u8bbf\u95ee\uff0c\u8be5\u600e\u4e48\u529e\uff1f\n<\/p>\n<p>\n\t\u7b54\u6848\u662f\u5728 src\/main\/resources \u4e0b\u65b0\u5efa application.properties \u6587\u4ef6\uff0c\u91cc\u9762\u52a0\u5165\u4e0b\u9762\u7684\u914d\u7f6e\u5373\u53ef\u3002\n<\/p>\n<pre class=\"brush:plain;\">\r\nserver.port=8090\r\nspring.application.name=test\r\nserver.context-path=\/xttblog<\/pre>\n<p>\n\t\u60f3\u8981\u81ea\u5b66\u7684\u4e5f\u53ef\u4ee5\u5230&nbsp;<a href=\"https:\/\/github.com\/spring-projects\/spring-boot\" name=\"spring-boot\" target=\"_blank\" title=\"spring-boot\">https:\/\/github.com\/spring-projects\/spring-boot<\/a> \u4e0a\u67e5\u770b\u5b98\u65b9\u6587\u6863\u8fdb\u884c\u81ea\u5b66\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2661\">\u4f7f\u7528 SpringBoot \u521b\u5efa web \u9879\u76ee<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u8001\u5b9e\u8bf4\uff0cweb \u9879\u76ee\u548c\u975e web \u9879\u76ee\uff0c\u6ca1\u4ec0\u4e48\u5927\u7684\u533a\u522b\u3002\u65e0\u975e\u662f src\/main\/resources \u4e0b\u653e\u4e0d\u653e [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1616,69,1522,1614,1615],"class_list":["post-2661","post","type-post","status-publish","format-standard","hentry","category-java","tag-freemarker","tag-java","tag-springboot","tag-thymeleaf","tag-velocity"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2661"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2661\/revisions"}],"predecessor-version":[{"id":2662,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2661\/revisions\/2662"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}