{"id":4413,"date":"2021-12-06T11:21:11","date_gmt":"2021-12-06T03:21:11","guid":{"rendered":"http:\/\/123.57.164.21\/?p=4413"},"modified":"2021-12-06T11:21:11","modified_gmt":"2021-12-06T03:21:11","slug":"spring-boot-starter-web%ef%bc%88web%e5%90%af%e5%8a%a8%e5%99%a8%ef%bc%89","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=4413","title":{"rendered":"spring-boot-starter-web\uff08Web\u542f\u52a8\u5668\uff09"},"content":{"rendered":"\n<p>Spring MVC \u662f Spring \u63d0\u4f9b\u7684\u4e00\u4e2a\u57fa\u4e8e MVC \u8bbe\u8ba1\u6a21\u5f0f\u7684\u8f7b\u91cf\u7ea7 Web \u5f00\u53d1\u6846\u67b6\uff0c\u5176\u672c\u8eab\u5c31\u662f Spring \u6846\u67b6\u7684\u4e00\u90e8\u5206\uff0c\u53ef\u4ee5\u4e0e Spring \u65e0\u7f1d\u96c6\u6210\uff0c\u6027\u80fd\u65b9\u9762\u5177\u6709\u5148\u5929\u7684\u4f18\u8d8a\u6027\uff0c\u662f\u5f53\u4eca\u4e1a\u754c\u6700\u4e3b\u6d41\u7684 Web \u5f00\u53d1\u6846\u67b6\u4e4b\u4e00\u3002<br>\u00a0<br>Spring Boot \u662f\u5728 Spring \u7684\u57fa\u7840\u4e0a\u521b\u5efa\u4e00\u6b3e\u5f00\u6e90\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86 spring-boot-starter-web\uff08Web \u573a\u666f\u542f\u52a8\u5668\uff09 \u6765\u4e3a Web \u5f00\u53d1\u4e88\u4ee5\u652f\u6301\u3002spring-boot-starter-web \u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5d4c\u5165\u7684 Servlet \u5bb9\u5668\u4ee5\u53ca SpringMVC \u7684\u4f9d\u8d56\uff0c\u5e76\u4e3a Spring MVC \u63d0\u4f9b\u4e86\u5927\u91cf\u81ea\u52a8\u914d\u7f6e\uff0c\u53ef\u4ee5\u9002\u7528\u4e8e\u5927\u591a\u6570 Web \u5f00\u53d1\u573a\u666f\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Spring Boot Web \u5feb\u901f\u5f00\u53d1<\/h5>\n\n\n\n<p>Spring Boot \u4e3a Spring MVC \u63d0\u4f9b\u4e86\u81ea\u52a8\u914d\u7f6e\uff0c\u5e76\u5728 Spring MVC \u9ed8\u8ba4\u529f\u80fd\u7684\u57fa\u7840\u4e0a\u6dfb\u52a0\u4e86\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n\n\n\n<ul><li>\u5f15\u5165\u4e86&nbsp;ContentNegotiatingViewResolver \u548c BeanNameViewResolver\uff08\u89c6\u56fe\u89e3\u6790\u5668\uff09<\/li><li>\u5bf9\u5305\u62ec WebJars \u5728\u5185\u7684\u9759\u6001\u8d44\u6e90\u7684\u652f\u6301<\/li><li>\u81ea\u52a8\u6ce8\u518c&nbsp;Converter\u3001GenericConverter \u548c Formatter \uff08\u8f6c\u6362\u5668\u548c\u683c\u5f0f\u5316\u5668\uff09<\/li><li>\u5bf9 HttpMessageConverters \u7684\u652f\u6301\uff08Spring MVC \u4e2d\u7528\u4e8e\u8f6c\u6362 HTTP \u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u6d88\u606f\u8f6c\u6362\u5668\uff09<\/li><li>\u81ea\u52a8\u6ce8\u518c MessageCodesResolver\uff08\u7528\u4e8e\u5b9a\u4e49\u9519\u8bef\u4ee3\u7801\u751f\u6210\u89c4\u5219\uff09<\/li><li>\u652f\u6301\u5bf9\u9759\u6001\u9996\u9875\uff08index.html\uff09\u7684\u8bbf\u95ee<\/li><li>\u81ea\u52a8\u4f7f\u7528 ConfigurableWebBindingInitializer<\/li><\/ul>\n\n\n\n<p>\u53ea\u8981\u6211\u4eec\u5728 Spring\u00a0 Boot \u9879\u76ee\u4e2d\u7684 pom.xml \u4e2d\u5f15\u5165\u4e86 spring-boot-starter-web\u00a0\uff0c\u5373\u4f7f\u4e0d\u8fdb\u884c\u4efb\u4f55\u914d\u7f6e\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 Spring MVC \u8fdb\u884c Web \u5f00\u53d1\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u793a\u4f8b\u00a0<\/h5>\n\n\n\n<p>1. \u521b\u5efa\u4e00\u4e2a\u540d\u4e3a spring-boot-springmvc-demo1 \u7684 Spring Boot \u5de5\u7a0b\uff0c\u5e76\u5728\u5176 pom.xml \u7684dependencies \u8282\u70b9\u4e2d\u6dfb\u52a0 spring-boot-starter-web \u7684\u4f9d\u8d56\uff0c\u4ee3\u7801\u5982\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    &lt;dependency>\n        &lt;groupId>org.springframework.boot&lt;\/groupId>\n        &lt;artifactId>spring-boot-starter-web&lt;\/artifactId>\n    &lt;\/dependency><\/pre>\n\n\n\n<p>2. \u5728 net.biancheng.www \u5305\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a HelloController\uff0c\u4ee3\u7801\u5982\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    package net.biancheng.www.controller;\n    import org.springframework.stereotype.Controller;\n    import org.springframework.web.bind.annotation.RequestMapping;\n    import org.springframework.web.bind.annotation.ResponseBody;\n    @Controller\n    public class HelloController {\n        @ResponseBody\n        @RequestMapping(\"\/hello\")\n        public String hello() {\n            return \"www.biancheng.net\";\n        }\n    }<\/pre>\n\n\n\n<p>3. \u542f\u52a8 Spring Boot\uff0c\u6d4f\u89c8\u5668\u8bbf\u95ee\u201chttp:\/\/localhost:8080\/hello\u201d\uff0c\u7ed3\u679c\u5982\u4e0b\u56fe\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/12\/image-127-1024x333.png\" alt=\"\" class=\"wp-image-4414\" width=\"639\" height=\"208\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-127-1024x333.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-127-300x98.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-127-768x250.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-127-830x270.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-127-230x75.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-127-350x114.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-127-480x156.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-127.png 1044w\" sizes=\"(max-width: 639px) 100vw, 639px\" \/><\/figure><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u6ce8\u610f\uff1a\u7531\u4e8e\u00a0spring-boot-starter-web \u9ed8\u8ba4\u66ff\u6211\u4eec\u5f15\u5165\u4e86\u6838\u5fc3\u542f\u52a8\u5668 spring-boot-starter\uff0c\u56e0\u6b64\uff0c\u5f53 Spring Boot\u00a0 \u9879\u76ee\u4e2d\u7684 pom.xml \u5f15\u5165\u4e86\u00a0spring-boot-starter-web \u7684\u4f9d\u8d56\u540e\uff0c\u5c31\u65e0\u987b\u5728\u5f15\u5165 spring-boot-starter \u6838\u5fc3\u542f\u52a8\u5668\u7684\u4f9d\u8d56\u4e86\u3002<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Spring MVC \u662f Spring \u63d0\u4f9b\u7684\u4e00\u4e2a\u57fa\u4e8e MVC \u8bbe\u8ba1\u6a21\u5f0f\u7684\u8f7b\u91cf\u7ea7 Web \u5f00\u53d1\u6846\u67b6\uff0c\u5176\u672c\u8eab\u5c31\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4413"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4413"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4413\/revisions"}],"predecessor-version":[{"id":4415,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4413\/revisions\/4415"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}